Path: senator-bedfellow.mit.edu!faqserv From: Sunil Rao Newsgroups: alt.comp.lang.learn.c-c++,comp.lang.c,comp.lang.c++,comp.lang.c.moderated,alt.answers,comp.answers,news.answers Subject: [alt.comp.lang.learn.c-c++] - FAQ list Supersedes: Followup-To: poster Date: 2 Sep 1998 11:56:04 GMT Organization: none Lines: 587 Approved: news-answers-request@MIT.EDU Expires: 16 Oct 1998 11:54:14 GMT Message-ID: NNTP-Posting-Host: penguin-lust.mit.edu Summary: This post contains useful information for anyone wishing to learn C and C++, listing online tutorials and resources, giving book recommendations and helping clear some common misconceptions. X-Last-Updated: 1998/09/01 Originator: faqserv@penguin-lust.MIT.EDU Xref: senator-bedfellow.mit.edu alt.comp.lang.learn.c-c++:7666 comp.lang.c:323574 comp.lang.c++:340522 comp.lang.c.moderated:9607 alt.answers:36499 comp.answer Archive-name: C-faq/learn Posting-Frequency: monthly Last-modified: 1 September 1998 URL: http://www.raos.demon.co.uk/acllc-c++/faq.html This document is a FAQ list for the newsgroup alt.comp.lang.learn.c-c++. It provides you with a framework and a set of guidelines for posting here, in addition to answering a number of questions newcomers here tend to ask. This FAQ is meant to be read in its entirety. This is the plaintext version of this list. An HTML version can be located at http://www.raos.demon.co.uk/acllc-c++/faq.html Written by Sunil Rao . Comments, suggestions, corrections and constructive criticism will be gratefully acknowledged. Last update: 1 September 1998 Last changes made: Updated the answers to Qs 7, 9 and 10. Special Thanks to... Dennis Swanson, Jim Gewin, Billy Chambless, Mark Brown, Dave Dunfield, Jack Klein, Steve Summit, Steve Clamage, Dennis Ritchie, Kaz Kylheku, Lars Hecking and Pablo Halpern for their helpful comments, suggestions, advice, corrections and constructive criticism, and (in the case of some) for permitting me to quote from their papers/posts. 1: What is the purpose of this newsgroup? alt.comp.lang.learn.c-c++ is an unmoderated newsgroup for the discussion of issues that concern novice and non-expert programmers in C and C++ who wish to *LEARN* more about one or both of these languages. 2: What is C/C++? First of all, C and C++ are different languages. C was created by Dennis Ritchie as an efficient language for systems programming. Bjarne Stroustrup then extended C by adding features to support object-oriented programming. C++ can be considered to be a superset of C, but there are real differences between them. 3: So, are C and C++ not so similar after all? They are indeed similar to a great extent. Incompatibilities do exist, though, and many idiomatic constructs used in C are frowned upon by C++ experts. C++ programmers generally consider code that does not exploit those features of C++ that make it possible to write better programs - programs that are more readable and easier to write and maintain - to be in poor style. The differences between the two languages are significant enough to ensure that one has to be clear about the language being used. However, it must not be forgotten that C++ is a largely a superset of C, and that it is possible (though perhaps not desirable) to write code that works correctly in both languages. 4: What is the difference between this newsgroup and comp.lang.c or comp.lang.c++? This newsgroup is primarily intended for discussion related to the LEARNING of C and C++. The other two groups are primarily intended for discussion of the features of the respective languages themselves. Naturally, some overlap does occur. This group does tend to be slightly (perhaps excessively so) more informal, though. 5: What kind of questions may be asked here? Any question relating to any aspect of C or C++ that you're having trouble understanding is on topic here. By C, what is meant is the language PROPER and its standard library as defined by ANSI and ISO. C++ discussions are about the proposed language standard (that recently passed its formal vote) and the library it defines. Any questions relating to specific compilers, third-party or non-standard libraries, compiler extensions etc are unwelcome here, and will probably be answered with a redirection to a more appropriate newsgroup. 6: I have a burning question about XXX. What should I do first? First of all, do check to see if your question has not been been answered before. Look up any of the standard references on the language. If you can't find the answer, browse the group, lurk here for a few days, search the archives at Dejanews, read the relevant FAQs (including those of comp.lang.c and comp.lang.c++), and if you STILL can't find the answer, post by all means. Note that you might not be the first ever learner to have run into your problems. There is a good chance that your question has been answered before. Dejanews: http://www.dejanews.com/ C FAQ: http://www.eskimo.com/~scs/C-faq/top.html C++ FAQ: http://www.cerfnet.com/~mpcline/c++-faq-lite/ 7: What other points should I make note of BEFORE posting here? Please observe basic Netiquette guidelines. If you're not sure of what these are, subscribe to news.announce.newusers, and read *ALL* of the posts there. To summarise these points very briefly - ensure that your post is on topic. Do your homework before posting. Don't post the same question one hundred times. Don't troll. Don't post homework questions without anything to show your effort. Don't ask for replies to be sent by email. Don't post binaries. Make sure that your subject line is an accurate description of the problem/topic. Please do not ask for replies by email. If you haven't got the time or patience to read the newsgroup, that's tough. The answers you receive might benefit other readers of the newsgroup as well, and you yourself might learn more from the discussions your question might generate. If you have to reply, be accurate and precise - your reply is being read by LEARNERS, remember. If you are unsure or have nothing new to add, don't bother. For heaven's sake, don't get abusive when you are corrected or redirected. If you are unsure as to why you have been redirected, ask the person who did so *PRIVATELY* by email. Do not take any answers on trust. Sadly, many of those who post answers here know even less than the interested learner who posted the original question. Wait for a few days before relying on any posted code or answers, just in case they might be corrected by others. Please do not make any MIME or UUENCODED posts (this includes HTML). Many newsreaders cannot handle such posts correctly. You will only make it impossible for many to read your posts. And please try not to flame. This is a learners' group. Not everyone who posts here is aware of all the issues involved. A grumpy attitude only makes things difficult for everyone concerned. 8: Why are questions relating to Windows, Graphics, Sockets etc. off- topic here? Questions on these topics come up every so often here. C and C++ are languages, not operating systems. They come with limited, though highly useful, standard libraries. While any question relating to these libraries is relevant and most certainly on topic, a question relating to MFCs, for instance, is of absolutely no interest to a Unix expert. There exist newsgroups DEVOTED to these non-standard additions. It certainly makes more sense to post a question in a place where there is a greater chance of it being answered, and answered correctly. 9: What are some other related groups where I might post questions? (Answer adapted from the regular "Welcome to comp.lang.c" post by Billy Chambless and Tim Behrendsen) You *really* ought to be able to work out where to post by yourself. Please, please, please, for heavens' sake read the FAQs and lurk for a while before posting your questions. Please do not post to more groups than are necessary. Think carefully about the relevance of your post before you post to any of the newsgroups mentioned below. If you decide that your question is indeed relevant to more than one newsgroup and is not a FAQ, please cross-post rather than multi-post. Remember that many regular readers of this newsgroup also follow several of the other groups mentioned below. Note: if your news server does not carry the borland.* newsgroups, you might find it necessary to connect to forums.borland.com instead. * Language Issues C comp.lang.c, comp.lang.c.moderated C++ comp.lang.c++, comp.lang.c++.moderated x86 assembly comp.lang.asm.x86 * Non-language-specific Issues Algorithms comp.programming Graphics comp.graphics.algorithms * Compilers/Libraries The gcc compiler gnu.gcc DJGPP (gcc for DOS) comp.os.msdos.djgpp Borland C++ borland.public.cpp Borland C++Builder borland.public.cppbuilder Visual C++ microsoft.public.vc.ide_general MFC microsoft.public.vc.mfc comp.os.ms-windows.programmer.tools.mfc OWL borland.public.cpp.owl comp.os.ms-windows.programmer.tools.owl VCL borland.public.cppbuilder.vcl * Operating Systems/System Specifics DOS issues comp.os.msdos.programmer MS Windows comp.os.ms-windows.programmer.misc microsoft.public.win16.programmer.* microsoft.public.win32.programmer.* OS/2 comp.os.os2.programmer.misc Macintosh comp.sys.mac.programmer.misc General UNIX comp.unix.programmer Amiga comp.sys.amiga.programmer 10: HELP! My program does not work correctly. What do I do now? Before posting code here, try and make sure that it at least compiles correctly, even if it does not quite behave the way you intended it to. Try and localise your error to a particular function or section of code - most readers have no time to wade through pages of code (If you are unable to do this, you probably need to start again from scratch anyway.). Do NOT under any circumstances post all of your code as an attachment - many will simply ignore your post. Essentially, post the smallest complete program that manifests the problem. This makes it easier for the reader to answer your question. You might find that doing this enables you to answer your question yourself! Read the answer to the above question as well. And do learn how to use the debugger that came with your compiler. 11: What online tutorials exist for learning C and C++? The best online tutorial for C I have come across has got to be Steve Summit's class notes for the C courses he teaches. http://www.eskimo.com/~scs/cclass/cclass.html There are references to other C tutorials in his C FAQ as well. Vinit Carpenter maintains a list of resources for learning C and C++. Do note, however, that a fair number of the tutorials placed online contain mistakes and/or are out of date. http://www.cyberdiem.com/vin/learn.html See also the answer to question 15. 12: What are the best books that teach C or C++? Opinions vary widely. Many learnt C from the "Bible" - "The C Programming Language", by Brian Kernighan and Dennis Ritchie. The second edition of this hallowed reference describes ANSI C. This book is rather heavy going for an absolute beginner, though. Other recommended books include K N King's "C Programming: A Modern Approach", and Dietel and Deitel's "C: How to Program". I've been told that Jesse Liberty's "Teach yourself C++ in 21 days" is an excellent book, despite the name. Other books you might wish to consider are "Effective C++" by Scott Meyers, "C++ Primer" by Stanley B Lippman, "C++: How to Program" by Dietel and Dietel (again!), "C++ Primer Plus" by Stephen Prata, and "Thinking in C++" by Bruce Eckel. You could also look at "The C++ Programming Language", Third Edition, by Bjarne Stroustrup. It's very hard going, but it's an essential reference. Note that I have not read all of these books. These recommendations are based primarily on the positive comments made by others. Do make sure that you get the latest edition of any of these books you decide to purchase. Many C and C++ experts recommend against using ANY book written by a certain Herbert Schildt. To see why, read the answer to the following question. 13: Why do many experts not think very highly of Herbert Schildt's books? A good answer to this question could fill a book by itself. While no book is perfect, Schildt's books, in the opinion of many gurus, seem to positively aim to mislead learners and encourage bad habits. Do take a look at the following scathing articles. http://www.lysator.liu.se/c/schildt.html http://www.solon.com/~seebs/c/c_tcr.html The following humorous post also illustrates the general feeling towards Schildt and his books. http://www.qnx.com/~glen/deadbeef/2764.html 14: Where can I get a free C or C++ compiler? (Answer adapted from Joe Buck's FAQ for g++ and libg++.) * gcc gcc is a free C and C++ compiler from the Free Software Foundation available for many Unix-based systems. Its ports for other systems are also freely available. http://www.fsf.org/software/gcc/gcc.html ftp://prep.ai.mit.edu/pub/gnu/ egcs (the experimental gnu compiler system) is another free project (based on gcc). Check out http://www.cygnus.com/egcs/ The MS-DOS port (DJGPP) of gcc runs on a 386 or higher, and is a full 32-bit compiler. http://www.delorie.com/djgpp/ For a port of gcc that works on 32-bit Windows, look at http://www.cygnus.com/misc/gnu-win32/ For the Amiga, BeOS, and pOS, look at the GG port of gcc at http://www.ninemoons.com/GG/ EMX is a port of gcc to OS/2 that also works on DOS. http://www.os2ss.com/unix/emx09c/ * lcc lcc-win32 is a free C compiler available for 32-bit Windows. http://www.cs.virginia.edu/~lcc-win32/ It is based on the retargettable lcc system. http://www.cs.princeton.edu/software/lcc/ * Micro-C If you are looking for a free C compiler for MS-DOS that is easy to install and use, take a look at Micro-C, available from http://www.dunfield.com/ Do bear in mind, however, that it is not wholly compatible with the standard. The incompatibilites are well-documented, however. 15: What good websites/online references exist for C and C++? http://www.lysator.liu.se/c/ is an excellent resource for C, containing a number of extremely useful links and pointers. Check out the C++ Virtual Library for some useful C++ links. http://www.desy.de/user/projects/C++.html You may wish to look at the C Language Online Journal at http://www.cs.wustl.edu/~jxh/CLOJ/ For some useful code snippets (some portable; others not), check out Bob Stout's SNIPPETS archive at http://www.snippets.org/ Martin Leslie's C Programming reference site is at http://www.gator.net/~garyg/C/c.html Jamie Blustein's C Programming Language resources are at http://www.csd.uwo.ca/~jamie/.Refs/C-refs.html Scott McMahan's C Programmer's Notebook, which discusses a number of issues C programmers encounter as their experience grows, is at http://www.skwc.com/essent/prognotebook.html Also, check out The Mining Company's C/C++ site, http://cplus.miningco.com/ Jon Morris Smith's C++ resources directory, http://www.cs.bham.ac.uk/~jdm/cpp.html Robert Davies' list of online C++ references, http://nz.com/webnz/robert/cpp_site.html The #C++ site, http://www.cl.ais.net/morph/c++/main.html and Simo Salminen's Programmers' Oasis C and C++ page. http://www.utu.fi/~sisasa/oasis/oasis-cc++.html 16: Should I learn C before learning C++? According to a number of C++ experts, including its creator Bjarne Stroustrup, and Marshall Cline (the author of the C++ FAQ), the answer is no. Look up the C++ FAQ to see why Cline thinks you do not need to learn C before C++. 17: What is the difference between C++ and Visual C++? C++ is a programming language. Visual C++ is Microsoft's implementation of it. When people talk about learning Visual C++, it usually has more to do with learning how to use the programming environment, and how to use the Microsoft Foundation Classes (MFCs) for Windows rather than any language issues. Visual C++ can and will compile straight C and C++. 18: What is portability? Why are so many people concerned about it? C and C++ are languages that are not tied down to a particular platform. This means that, with care, it is possible to write useful code in either of these languages that will run on different platforms without modification. That is not to say that ALL code written in these languages must conform strictly to the standards - in practice it is sometimes neither possible nor desirable to achieve this aim. However, the job of porting code is made easier when any system-specific stuff is carefully packaged or abstracted away, so that it is clear and straightforward to make the necessary changes during a port. In order to be able to do this effectively, it is important to be aware of what can and can not be done within the realms of the standards set by these languages. That is why a lot of importance is placed on adhering strictly to the standards, at least while learning. 19: How do I BEGIN to write C or C++ under Visual or Borland C++? This question is, strictly speaking, off-topic, but is answered here since it's one that seems to plague many beginners. To start with, you need to make sure that you are not writing a Windows application. Try creating a new project or application to target MS-DOS, QuickWin or Win32 Console depending on your compiler version. You can then use the Standard C and C++ libraries to write strictly conforming programs. It's best to learn to write standard-conforming programs first before branching off into writing Windows programs. If you find that you are having a lot of trouble setting up your compiler, a good place to ask questions is a newsgroup devoted to your compiler. See Question 9 for a list of such groups. 20: HELP! My program seems to compile correctly, but when it runs, a DOS window flashes and then vanishes. This can sometimes occur when you are developing programs using an IDE. A command prompt window opens and displays the output, and control is passed back immediately to the IDE. To get around this, you can look through the various menus to find a "View Output Screen" option. Alternatively, you could open a command prompt window and change directory to the one your executable is going to end up in and run your executable directly from there. The solution of using a non-standard function to keep the executable running until a key is pressed is not a very good idea - especially if you are going to run your program outside of the development environment. 21: Why doesn't this FAQ cover language issues? This is because other better, more comprehensive resources exist for this purpose. See the answers to questions 11 and 15. 22: Where can I obtain a copy of the standards for C and C++? You cannot obtain copies of the standards online. This is because the standards organisations earn a large part of their revenue from selling printed copies. The C FAQ tells you how you can obtain copies of the C standard. The formal vote for the C++ standard has been passed, and the standard should be formally approved soon. If you are looking for the C standard, you can buy "The Annotated ANSI C Standard", by the afore-mentioned Herbert Schildt (question 13). Make sure that you ignore the annotations completely, however. 23: HELP! I get errors when I try to compile "hello, world"! Check your source to make sure you haven't missed any semi-colons or braces. Also remember that C and C++ are case-sensitive - Main() and main() are completely different, for instance. If you are satisfied that the program source is all right, then you probably have not set your compiler up properly. You might need to ask one of the experts in a newsgroup devoted to your compiler about this - see the answer to question 9. 24: Which language should I learn first - C or C++? The answer to this depends on your own inclinations. C is a smaller, less complex language than C++, and is consequently easier to master. However, it is probably easier to get up to speed with C++, if you make effective use of the standard library. Some find C to be more elegant than C++, others think it to be too "unsafe". C++ programmers generally feel that it has features that make it easier to write good, robust, readable and maintainable code in than in C. 25: Why are C and C++ so popular and widely-used? (First part of answer adapted from a March 1998 comp.lang.c post by Kaz Kylheku on "Why Has C Proved To Be Such A Succesful Language") C has always been a language that never attempts to tie a programmer down - it allows for easy implementation, it comes with a genuinely useful standard library that can itself be implemented in C, and it is both efficient and portable. C has always appealed to systems programmers who like the terse, concise manner in which powerful expressions can be coded. C was widely distributed with an Operating System (Unix) that was actually largely written in C itself. Also, C allowed programmers to (while sacrificing portability) have direct access to many machine-level features that would otherwise require the use of Assembly Language. As Dennis Ritchie writes in his paper, "The Development of the C Language", C is quirky, flawed, and an enormous success. While accidents of history surely helped, it evidently satisfied a need for a system implementation language efficient enough to displace assembly language, yet sufficiently abstract and fluent to describe algorithms and interactions in a wide variety of environments. C++ has its basis in C - extending it by supporting features meant to encourage and support the development of large programs. Perhaps most importantly, it supports object-oriented programming in a familiar setting and framework (that of C). When C++ was created, one of the initial aims was to retain compatibility with C to as large an extent as possible, and retain its spirit and efficiency. It was possible to convert from C to C++ gradually, thus making use of C++ (initally, at least) as a "better C", and moving on to using other features. This allowed many C programmers to learn C++ quickly (though it required a major mind-shift). 26: Why is this FAQ so grumpy/terse/curt/unfriendly? A lot of questions posted in alt.comp.lang.learn.c-c++ are posted by people who are generally unsure about what they are learning. Many beginners fail to appreciate that C and C++ are used on a number of platforms, and that what works with a particular compiler is not necessarily going to work with another, even on the same platform. It is important that a learner be clear about the differences between programming in standard C or C++, and programming using platform- and compiler-specific extensions. In the long run, this approach - that of separating the idea of "language" and "platform" - leads to a better understanding of both the language and the platform. It is generally accepted that the sooner this is appreciated by the learner, the better. This is the only reason for grumpiness - most interested learners find alt.comp.lang.learn.c-c++ a very pleasant and helpful place once they understand this. The newsgroup is nowhere near as grumpy as this FAQ might suggest - certainly not towards someone who has read and understood all it has to say!