The alt.comp.lang.learn.c-c++ FAQ

This document is a FAQ list for the newsgroup alt.comp.lang.learn.c-c++. It provides readers with a framework and a set of guidelines for posting to the newsgroup, in addition to answering a number of questions newcomers tend to ask.

This FAQ is meant to be read in its entirety. Planned distribution: fortnightly to alt.comp.lang.learn.c-c++, and monthly to comp.lang.c, comp.lang.c++, comp.answers, alt.answers and news.answers.

This is the HTML version of the FAQ. It is updated with each alteration in the plain text version, the latest release of which can always be obtained via anonymous FTP from:

ftp://snurse-l.org/pub/acllc-c++/faq
or via HTTP from:
http://snurse-l.org/acllc-c++/

The following other FAQs may be considered essential reading:

C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
C++ FAQ: http://marshall-cline.home.att.net/cpp-faq-lite/
This document was originally compiled and maintained by Sunil Rao. Revised & updated in 2001 by Rich Churcher - see Appendix B for a list of contributors. Comments, suggestions, corrections, constructive criticism and requests for clarification will be gratefully received.

The alt.comp.lang.learn.c-c++ regulars would like to thank Sunil for his hard work developing this FAQ, and his generosity in donating it for future use by the newsgroup.

Current maintainer: Rich Churcher. Last update: 29 September 2001


Table of Contents


1.1 What is the purpose of this newsgroup?

alt.comp.lang.learn.c-c++ is a self-moderated newsgroup for the discussion of issues that concern novice to intermediate C and C++ programmers. We ask and answer questions about those languages as defined by their respective standard documents.

Please note: in speaking of C and C++ throughout this document, we are referring to the standard versions of each language. We are interested in the core languages, not in their respective compilers, implementations, or add-ons. See 2.5.

Exactly what questions are considered to be about the standard C and C++ languages may be difficult for a newcomer to understand. We recommend you read the remainder of this FAQ, which should help you understand what we would consider "off-topic".

That probably looks scary. Basically, anybody can post to the group. Provided the questions you post are on-topic and the answers you provide are accurate, you should not have a problem. If your question is off-topic, you will typically be redirected to a newsgroup that is more appropriate (see 8.1); if your answers are inaccurate, you risk being corrected politely but firmly.

Back to Contents


1.2 What is the difference between this newsgroup and comp.lang.c or comp.lang.c++?

This newsgroup is intended for discussion related to the practice and process of learning C and C++. The other two groups are primarily intended for general discussion of the features of those languages.

Naturally, some overlap does occur. This group does tend to be slightly more informal, though. Most regulars on this group show great patience with many common beginners' questions and will willingly expound on many topics of interest or particular difficulty, referring to appropriate reference material, either in printed or in electronic form, as necessary.

Back to Contents


1.3 I have a burning question about XXX. What should I do first?

Please take the following steps before posting your question to alt.comp.lang.learn.c-c++:

If after doing all these things 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.

See also:

Google Advanced Search: http://groups.google.com/advanced_group_search
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
C++ FAQ: http://marshall-cline.home.att.net/cpp-faq-lite/

Back to Contents


1.4 My program does not work correctly. What do I do now?

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. Please also specify if your code is C or C++, as the intended language is not always clear from context.

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. If you cannot achieve this, include all error messages and mark the lines that they refer to.

Essentially, POST THE SMALLEST COMPLETE PROGRAM THAN 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!

It usually helps if you set the warning levels to the highest possible for your compiler - let the compiler pick out errors and warn you of any potential problems. Do learn how to use the debugger that came with your compiler. Not only will you learn how to solve this problem, but also many others that you'll encounter as you begin to write more ambitious programs.

Back to Contents


1.5 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. A good reference is

http://www.ezine.com/netiquette.html
To summarise these points very briefly:

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. In addition, please ensure that your news software is set to post lines of a maximum length of around 60 to 70 characters (and even 70 is getting a bit long). This may seem pedantic, but when source code is being posted it becomes harder to read with each reply if the original lines were long.

Make sure that your subject line contains an accurate description of your problem or the topic of your post. Including one of the following tags:

[C]
[C++]
[C,C++]
in the subject line will assist regular readers in answering your question.

It usually helps if you INDICATE SOMEWHERE IN YOUR POST IF YOU'RE EXPECTING A C OR A C++ ANSWER - several techniques appropriate to C++ will not work in C, and some C programs will not work or are considered bad style under C++. It also makes it easier for other readers - they can then safely ignore your post if they cannot help you with it. If you're not sure as to which language you're learning, you probably need to get better resources to learn from.

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. This is also why it is a very bad idea to e-mail your questions directly to regulars; you have no insurance against any potential mistakes. Remember that no-one is infallible.

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.

Back to Contents


1.6 What kind of questions may be asked here?

Any question relating to any aspect of STANDARD C or C++ that you're having trouble understanding is on topic here.

By C, what is meant is the standard language and its standard library as defined by ISO/IEC 9899:1999.

By C++, what is meant is the standard language and its standard library as defined by ISO/IEC 14882:1998.

Although these published standards form the basis for our discussions, we will sometimes address issues related to previous versions of each language.

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 (see 8.1-5).

If you've been redirected, do not get miffed or upset and post an angry response - it will cut no ice with the regulars and will only label you as an unwilling learner. What's discussed in this group is rigidly defined to limit the traffic and make the group useful to as wide an audience as possible.

Back to Contents


1.7 I think I can answer that question!

Sometimes it's tempting to leap right in and start trying to solve problems you see posted to alt.comp.lang.learn.c-c++. Sometimes the answer seems obvious. However, please wait awhile before you do this, especially if you are just beginning to learn the language in question. We recommend that you spend a good deal of time reading the group silently prior to contributing an answer - say, one or two months.

A good rule of thumb is to write a few responses but keep them saved on disk. Then, as the responses from newsgroup regulars trickle in, compare your answer with theirs. You'll learn a lot that way, and save yourself some embarrassment!

When you feel you're ready to contribute to answering questions in this newsgroup, please remember your target audience - students, often beginners. With that in mind, please take care to be clear and accurate. Please check your code carefully and compile it before posting.

And please don't send answers to private e-mail. It's best if your work is checked - even experienced programmers make mistakes.

Back to Contents


1.8 Why are requests for private e-mail responses frowned upon?

Please do not ask for replies by e-mail. 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.

In addition, alt.comp.lang.learn.c-c++ operates a kind of informal peer review whereby any answers posted publicly to the group are checked by seasoned programmers for their accuracy and clarity. Obviously, we can't check an answer sent to your private e-mail address.

Back to Contents


2.1 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 later 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.

It can usually (though not always) be assumed that anybody who talks about "C/C++" as one language is no expert - this extends to book authors too. It is normally unclear whether somebody is referring to "C OR C++" or "C AND C++" when using this expression, so it is probably best avoided.

Back to Contents


2.2 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, and vice versa. C++ programmers generally consider C++ 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.

A lot of people believe incorrectly that object-oriented programs cannot be written in C; this is not true. What is true is that C++ provides features that make it easier to write in a style that is object-oriented; in other words, C++ supports programming in an object-oriented style.

However, don't make the mistake of thinking that object-oriented programming is the only way to program in C++. C++ supports generic programming with its template features (using the same code for different types); object-based programming; procedural programming (as often found in C programs); and other programming paradigms.

See also:

The C++ Programming Language, Appendix B
[ Discusses incompatibilities between C and C++ ]
http://www.research.att.com/~bs/3rd_compat.pdf

Back to Contents


2.3 Do I have to 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 a firm no.

Look up the C++ FAQ to see why Cline thinks you do not need to learn C before C++. A post by Bjarne Stroustrup to comp.lang.c++ addresses this point too.

http://www.research.att.com/~bs/learn.html
Learning Standard C++ as a New Language, a paper by Stroustrup, examines this much-debated issue in great depth. The paper is aimed more at educators than at beginners.
http://www.research.att.com/~bs/papers.html
However, others as thoughtful as Stroustrup and Cline disagree. If you believe you will ever need to program in C, then in might make sense to learn C first.

Back to Contents


2.4 So 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++, but that does not necessarily make it easier to master. There are C++ features which accomplish tasks that would have to be coded "by hand" in C. The more extensive C++ standard library provides features which can lead students to writing useful programs fairly quickly. However, C++ syntax can be daunting and its behaviour mysterious at times.

Some find C to be more elegant than C++, others think it to be too "unsafe". Some C++ programmers feel that it has features that make it easier to write good, robust, readable and maintainable code in than in C.

But there are a vast number of programs written in idiomatic C, and some C++-only programmers find them difficult to read easily, providing an argument that you might like to become fluent in both languages, and this might influence the order in which you learn them.

Back to Contents


2.5 What is the difference between C++ and Visual C++?

Newcomers to the newsgroup often ask this without realising that Visual C++ isn't a language at all. Visual C++ is the Microsoft C++ implementation for Windows, one vendor's C++ distribution with extensions that are intended to aid programming in the MS Windows environment.

If the word "implementation" is confusing, just think "compiler". The words are sometimes used interchangeably, although strictly speaking a compiler is only one part of an implementation.

One of the tasks new C and C++ programmers have to accomplish is learning the difference between the standard languages and their various implementations. This task is often made more difficult due to bugs or incompatibilities in the implementation, as well as the many extensions and additional facilities that vendors make available.

On alt.comp.lang.learn.c-c++, we try to point out the differences wherever we can. Newcomers to the group often complain that this is unnecessarily pedantic or harsh, but in actual fact we're doing you a favour - if you understand the difference, you will find the process of moving between operating systems in your programming career is far easier! You will even be able to move more smoothly between compilers on the same platform.

C and C++ are languages. They exist as an idea, a set of rules, a grammar which is documented in their respective standard documents. In order to do anything useful, they must be IMPLEMENTED. Get used to this word, you'll be hearing it a lot more. Simply put, implementation means to take an idea or a set of instructions, and make it concrete. Make it happen.

Languages: C, C++
Implementations: MS Visual C++, Borland C++ Builder, GCC
See the difference? This newsgroup deals with the languages, not the implementations.

See also:

http://www.comeaucomputing.com/techtalk/#vc

Back to Contents


2.6 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 often 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.

Our classic example is one which we are confronted with many times on the newsgroup: "How do I clear the screen?" (see 4.2) Most beginners think that this seemingly simple task should be easily accomplished. However, it's important to remember that C and C++ compilers exist on a huge number of different hardware architectures and operating systems. What works on Windows won't work on an iMac. The hardware call which wipes the screen of a Point Of Sale terminal is different to that which removes objects from air traffic control screens.

Because there is no "one size fits all" solution for clearing the screen, a good programmer might try to restrict all screen clearing code to one part of her program, then call that part repeatedly from elsewhere. When she came to port the program to another operating system, only that small part would need to be replaced.

Back to Contents


2.7 Where can I obtain a copy of the standards for C and C++?

You cannot obtain copies of the standards for free. This is because the standards organisations earn a large part of their revenue from selling printed copies.

The C standard (ISO/IEC 9899:1999) can be purchased online directly from the American National Standards Institute (ANSI) Electronic Standards store. After registering yourself for free, you can download the document in Adobe PDF format on payment of $20.00 (US) by credit card. The standard is also available from the International Standards Organisation (ISO) website, but it will cost you more.

ANSI
http://webstore.ansi.org/
ISO
http://www.iso.ch/cate/d29237.html
The C++ standard (ISO/IEC 14882:1998) can be downloaded from the ANSI store for $18 (US), or you can order through ISO (again, at a higher cost).
ISO
http://www.iso.ch/cate/d25845.html
The standard documents can be daunting at first sight. They are intended to be as formal and precise as possible. They are NOT suitable for learning from, but are to be used as the ultimate authority with regard to any language issue.

Your country might have a standards organization from which the language standards can be obtained. See the comp.std.c++ FAQ for a brief list of some of those organizations.

See also:

The comp.std.c++ FAQ
http://www.research.att.com/~austern/csc/faq.html

Back to Contents


2.8 Why are C and C++ so popular?

(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 Successful 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.
A somewhat different argument is made in Worse is Better, by Richard Gabriel in section 2.1.
http://www.naggum.no/worse-is-better.html
C++ has its basis in C - extending it by providing features meant to encourage and support the development of large programs. One of its most appealing attributes is its multi-paradigmed nature - it supports a variety of different programming styles, especially object oriented programming, generic programming, procedural programming.

In The C++ Programming Language, Bjarne Stroustrup writes:

By supporting several programming paradigms, C++ supports productive programming at several levels of expertise. Each new style of programming adds another tool to your toolbox, but each is effective on its own and each adds to your effectiveness as a programmer. C++ is organized so that you can learn its concepts in a roughly linear order and gain practical benefits along the way. This is important because it allows you to gain benefits roughly in proportion to the effort expended.
[ Special edition, 1.2, p7 ]

Back to Contents


2.9 C++ is better than C because it's object-oriented, right?

Get out of the habit of thinking that one language is "better" than another. Better for what? You will find that most alt.comp.lang.learn.c-c++ regulars advise picking the right language for the right job. It pays to become conversant in more than one language, and use different techniques to solve different problems. Many real-world programming tasks are accomplished using a variety of languages and techniques together.

Besides, C++ is not solely an object-oriented language. It provides facilities for a number of different styles (see 2.8). Again, it's a matter of choosing the best method for the task at hand.

Most programmers will find that to become truly effective they need to learn more than one language. Many professionals know and use both C and C++, although most express a preference for one or the other.

Back to Contents


2.10 C is out of date and nobody uses it any more, right?

Wrong. The C language is in widespread use throughout the world. In fact, it's quite likely that you have some device in your household programmed in C, whether you realise it or not. There is a massive amount of C legacy code which will need to be maintained for many years to come.

Don't buy in to those arguments that claim C is dead or dying. C is one of the most successful languages ever designed. It will be around for some time to come for two simple reasons: first, there exist compilers for virtually every architecture you care to name; second, for many tasks no-one has come up with a viable alternative.

Furthermore, the C standard was revised in 1999. Its popularity shows little sign of waning.

Back to Contents


2.11 Can I program games in C or C++?

Yes. Many games are written using these languages. One of the more well-known examples is the Quake series, written in C.

However, writing games often involves using platform-specific extensions, and writing good games takes good programmers. For many beginners it is much better to first learn standard C or C++, learn programming, and only then move on to writing that sequel for Carmageddon.

See also:

4.6 How do I create and display graphics?

Back to Contents


2.12 What else are C and C++ used for?

You name it. Although perhaps best suited for systems-level programming, both C and C++ are also used in high-level applications development. Common areas of use include:

The versatility of both languages has led to an extremely large installed base covering most disciplines of computer science, including niches in communications and internet programming. Libraries are readily available (often for free) to accomplish all kinds of tasks.

Back to Contents


3.1 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 8.4.

The sole reason for redirecting compiler setup questions to other groups is to reinforce the point that a language is inherently separate from an implementation of one. There are simply too many different implementations of C and C++, and too many subtleties involved in the actual learning of C and C++ for all of them to come under the banner of this newsgroup.

Back to Contents


3.2 I posted a homework question, but got no help; only sarcastic responses. Why?

Many students post requests for us to do their homework for them - attempts to disguise this usually do not work particularly well. You will typically receive no help unless you can demonstrate that you have made an honest attempt to solve the problem yourself, by posting some code you have trouble with, for instance. Questions about homework assignments are generally welcome, as long as you show some effort and have bothered to think about the problem prior to posting

There is little point in a regular supplying you with code to fulfil an assignment if you are going to pass the course and come out and work on real-world projects without knowing how to even tackle a basic homework problem.

See also:

http://home.att.net/~jackklein/ctips01.html#homework
http://members.xoom.com/jshiva/hw.txt

Back to Contents


3.3 Why does everyone say my question is off-topic? I'm learning, and this is alt.comp.lang.LEARN.c-c++!

First of all, that uppercase "LEARN" is a cliche, so don't think you're being clever. We see it approximately once a fortnight.

Please see 2.5. Note the emphasis on LANGUAGE vs. IMPLEMENTATION. Implementation-related questions (such as those regarding the Microsoft or Borland compilers, or the MS Windows operating system) are better answered in newsgroups designed specifically for such tasks - see 4.2-7 for examples of such questions, and 8.1-5 for the newsgroups in which they belong.

Newcomers to alt.comp.lang.learn.c-c++ frequently want information on these topics or help with other system-specific issues. We often receive requests for help with compilers, debuggers, linkers, libraries, and so on.

However, most of the regulars believe that learning the core language without all those other bits and pieces the implementation provides (graphics, sound, lights, magic) is the best way to begin. We foster that approach by discussing ONLY the C and C++ languages as defined by their respective standards.

See also:

http://home.att.net/~raffles1/how_to_get_help.htm
http://members.xoom.com/jshiva/offtopic.txt

Back to Contents


3.4 Why does everyone make so much fuss about "void main()"?

Because the return type of the main() function must be int in both C and C++. Anything else is undefined. Bottom line - don't try to start a thread about this in alt.comp.lang.learn.c-c++ as it has already been discussed many, many times and generates more flamage than any other topic.

See also:

http://www.eskimo.com/~scs/C-faq/q11.12.html
http://home.att.net/~jackklein/ctips01.html#int_main
http://www.comeaucomputing.com/techtalk/#voidmain

Back to Contents


3.5 What's the difference between <iostream> and <iostream.h>?

<iostream> is the correct standard C++ header name. <iostream.h> does not exist according to the ISO standard, but many compilers still provide it because it remains common in legacy code. It should not be used where an implementation provides the header <iostream>.

Standard C++ headers do not have the `.h' suffix. They look like this:

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

These headers can be implemented in any fashion, as long as they meet the standard requirements. Theoretically, they could be a block of memory, a strip of magnetic tape, or stored on a Babbage Difference Engine for all we know. Of course, the actual representation of the header is likely to be an ordinary text file under most implementations, but it does not need to be named "iostream.h". For this reason, and to avoid name clashes with C headers, the `.h' has been dropped.

See also:

3.6 What's the difference between <string> and <string.h>?

Back to Contents


3.6 What's the difference between <string> and <string.h>?

<string> is the C++ header which defines the std::string class. <string.h> is a C header which defines such functions as strcpy(), strlen(), and strcmp(). Although standard C++ does provide a <string.h> header, the use of it is deprecated in favour of <cstring>.

Confused? Well, when C++ was standardised it was decided to retain the C standard library. If the `.h' suffix was dropped from the C headers, this would cause name clashes with C++ headers. To avoid this, the letter `c' was added to the beginning of each C header name. Thus:

<string.h> became <cstring>
<stdio.h> became <cstdio>
<stdlib.h> became <cstdlib>
and so on.

What does this mean for your own programs? Well, you should always prefer the C header names without the suffix. These provide functions defined in namespace std, as opposed to the old headers whose contents are defined in global space. In addition, <string.h> and its kin are deprecated by the C++ standard, which means that they might disappear in a later version.

See also:

3.5 What's the difference between <iostream> and <iostream.h>?

Back to Contents


4.1 My program seems to compile correctly, but when it runs, a console window flashes and then vanishes.

This can sometimes occur when you are developing programs under Microsoft Windows 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, change directory to the one your containing your executable, and run it from there.

Back to Contents


4.2 How do I clear the screen?

Short answer - this is not possible using standard C or C++.

This is the issue newcomers to our newsgroup have the most trouble with. We're sorry, really we are, but there is just NO WAY of clearing the screen in standard C or C++. Truly.

Why? Well, to begin with, define "clear the screen". Do you mean, clear one window of a windowed operating system? Clear every pixel currently displayed on a monitor? Remove all text from a command line interface? Scroll dots off an LED display?

There are so many different combinations of hardware and software which C and C++ must act on that it is not possible to provide one solution that fits them all. For this reason, you'll need to ask the question in a newsgroup which deals with your particular operating system, hardware, or compiler.

Because there is no standard way to clear the screen, we can't provide you with an appropriate answer in alt.comp.lang.learn.c-c++. Please don't ask us how to clear the screen. The question has been asked so many times it has passed through the realms of cliche and out the other side into mythology.

See also:

http://www.comeaucomputing.com/techtalk/#clearscreen

Back to Contents


4.3 How do I obtain a directory listing?

Because the means of doing this differs between operating systems, you'll need to ask this question in a forum for your C or C++ implementation or operating system. We simply can't give you an answer that will work on all systems - directories are not part of the C and C++ standards.

Back to Contents


4.4 How do I read a key without waiting for <ENTER>?

C and C++ provide stream-based I/O. In simple terms, this means that characters accumulate until they are read by a program or are destroyed - usually, this process involves a buffer of some kind so that data is made available one line at a time, not character by character. In addition, there can be multiple layers of buffering, some of which are part of the underlying operating system and are therefore outside the direct control of your program.

The program does not have to know about where the characters come from. They could be in a file, typed by someone sitting at a keyboard, or sketched on a touchpad for all we care.

This approach has the effect of distancing C and C++ programs from the hardware they run on. Now, in practice we realise that there are ways to read an individual key press or other single event such as a switch being thrown or a mouse movement - BUT those events are detected using code specific to the hardware in question, and as such are not a part of standard C or C++.

Because there are so many different ways of accomplishing such things, the best place to ask about them is in a newsgroup or mailing list which discusses your particular hardware or operating system.

See also:

http://www.eskimo.com/~scs/C-faq/q19.1.html
http://www.comeaucomputing.com/techtalk/#readonechar
http://www.calpoly.edu/~jfischer/c++faq/defs/blocking.html

Back to Contents


4.5 How do I access the serial port?

Because the means of doing this differs between operating systems, you'll need to ask this question in a forum for your C or C++ implementation or operating system. We simply can't give you an answer that will work on all systems - serial ports are not part of the C and C++ standards.

Back to Contents


4.6 How do I create and display graphics?

We lose count of the number of beginners who want to progress immediately from "Hello, world!" to writing the latest greatest turn-based strategy game, with all the trimmings.

Usually, our response to such yearnings is to counsel patience and a systematic approach to learning C or C++. First learn the standard language, THEN go nuts with graphics, sound, animation, windows, communications, or whatever takes your fancy. C and C++ are not simple languages. They take time and perseverance to learn. If you make the effort to learn the standard language first, sans graphics or any of the other tempting optional extras, you will find life much easier later on when creating more extensive programs.

You should be aware that the process of learning these languages to the point where you are able to write such complex programs may take a year or more, and a lot of hard work will be necessary to acquire the diverse skill set needed.

Having said that, let's be quite clear - we don't discuss graphics, sound, animation, or any of that stuff on alt.comp.lang.learn.c-c++ as they are not part of the C or C++ standards. You'll need to find a newsgroup or mailing list that deals with your particular compiler or operating system and ask your questions there.

Back to Contents


4.7 How do I use the printer or parallel port?

In standard C or C++, you probably can't. You'll need to use whatever additional libraries that came with your compiler to accomplish such tasks.

There is one caveat - under certain operating systems, you may be able to get away with opening a file and writing to it, which in turn writes to the printer. However, this is not something we can guarantee for every OS, therefore the question is off-topic in this newsgroup.

Back to Contents


5.1 Where can I get a free compiler for MS Windows?

MinGW

GCC distributed with native MS Windows32 libraries.

http://www.mingw.org/

Cygwin

Port of GCC and relevant tools providing a UNIX-like API on top of the Win32 API.

http://sources.redhat.com/cygwin/

Bloodshed Dev-C++

An IDE distributed with an MS Windows port of GCC and the Mingw32 runtime library.

http://www.bloodshed.net/devcpp.html

Borland compilers

A free version of Borland's C++ compiler is now available for download from:

http://www.inprise.com/bcppbuilder/freecompiler/

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/

Pacific C

The Pacific C compiler is available for free for personal use. You can download it from

http://www.hitech.com.au/products/pacific.html

Back to Contents


5.2 Where can I get a free compiler for Mac OS?

MPW

If you're programming under the Apple Macintosh, you can obtain the Macintosh Programmers' workshop for free.

http://developer.apple.com/tools/mpw-tools/

Apple Development tools

http://developer.apple.com/tools/#compilers

MAC OSX

http://developer.apple.com/macosx/

Back to Contents


5.3 Where can I get a free compiler for Unix or Linux?

GCC

GCC, the Gnu Compiler Collection, includes a free C and C++ compiler from the Free Software Foundation available for most Unix-based systems. It has been ported to many other systems (including Microsoft operating systems.)

http://gcc.gnu.org/

Back to Contents


5.4 I don't have any of those systems, but I still need a compiler!

For the Amiga, BeOS, and pOS, look at the GG port of GCC at

http://www.geekgadgets.org/

DJGPP

A popular GCC port for MS-DOS.

http://www.delorie.com/djgpp/

Comeau C++ Online

Test-compile code using this web interface for Comeau C++.

http://www.comeaucomputing.com/tryitout/

Back to Contents


5.5 I have some money to spend on a compiler, but not much. What do you recommend?

Often C and C++ implementations can be had for surprisingly little, especially if you happen to belong to a major university or college. Academic discount can get you very reasonable deals on "learning editions" of certain major compilers, as well as full versions. We suggest you ask your computer science department or college bookstore for recommendations and specials.

It's not really our place to endorse one implementation over another. The regulars use a wide variety of tools in their daily work. You'll need to do a bit of research to find the one that's right for you.

Back to Contents


6.1 What should I look for when picking a book to learn from?

Opinions vary widely. Many readers recommend the book(s) they learned from, regardless of whether or not they might actually be suitable for the student. The fact that many commonly recommended books are either full of errors or hopelessly out of date (or even both!) makes matters worse. Fluency of writing style and easy to understand explanations can hide technical inaccuracies, especially to a beginner.

Beware of books that claim to teach you both C and C++ - they might end up teaching you a horrible hybrid instead. It is also probably better to stick to books that conform to the C and C++ standards, at least while beginning. It's also valuable to get a recent text, given the changing nature of both languages, so check the copyright date.

Many compiler-specific books do not go into sufficient depth regarding important language issues and usually fail to be clear as to whether something is specific to the compiler under consideration or not. Some texts come bundled with compilers. It's usually worth checking to see how out of date the compiler actually is.

It pays to keep more than one good book handy; many books known for their technical accuracy can seem dense and unreadable in places, and you might at times need to back up a primer with a reference. Most alt.comp.lang.learn.c-c++ regulars will recommend that you learn from more than one book, and any serious programmer will quickly accumulate a library of texts.

Do make sure that you get the latest edition of any of these books you decide to purchase. Also please check to see if there is an errata list available online for any book you decide on; this is particularly important for programming language texts. It pays to be suspicious of books for which such lists cannot be located online.

The Association of C and C++ Users (ACCU) maintains a collection of book reviews taken from its journals. Many of the reviews are fair and excellent in their criticism, though there are a few minor inconsistencies and a number of truly awful books have escaped with favourable reviews. It's a useful starting point, though.

http://www.accu.org/bookreviews/public/
Many C and C++ experts recommend against using ANY book written by a certain Herbert Schildt. To see why, read 6.4. The "Dummies"/"Complete Idiots" series of books are not particularly well-regarded either.

Back to Contents


6.2 What are the best books I can learn C from?

If you wish to learn C, the classic text - the "Bible" - is The C Programming Language, 2nd edition, by Brian Kernighan and Dennis Ritchie. This hallowed text describes and explains ANSI C, but does not cover the C99 standard (ISO/IEC 9899:1999). For a FAQ explaining some of the changes contained in C99, please see:

http://www.comeaucomputing.com/techtalk/c99/
K&R2 is renowned for its brevity, clarity, elegance and completeness; but these very factors can make it heavy going for the beginner.
http://cm.bell-labs.com/cm/cs/cbook/
K N King's C Programming: A Modern Approach is another text frequently recommended on comp.lang.c. This book is a good, thorough introduction to C that is a lot easier to work with from a beginner's perspective.
http://knking.com/books/c/
See also:
http://users.powernet.co.uk/eton/clc/cbooks.html

Back to Contents


6.3 What are the best books I can learn C++ from?

The canonical text for C++ is The C++ Programming Language, 3rd edition, by Bjarne Stroustrup. Experienced C++ programmers love it; however, many beginners seem to find it very hard going indeed. Like K&R2, it assumes basic familiarity with programming concepts and is not really intended for the absolute beginner. It does not assume any previous knowledge of C.

http://www.research.att.com/~bs/about_3rd.html
Beginners are advised to obtain Stroustrup's hardcover "Special Edition", as it contains many corrections and new appendices which will be valuable later on.

A good starting point for C++ is Stan Lippman and Josee Lajoie's C++ Primer, a solid text with a strong focus on text processing and standard C++ programming. Both authors were active in development of the C++ standard. The book is eminently readable, and would be a good beginning for those with minimal programming experience. Published in 1998, it remains a valuable resource.

http://www.awl.com/cseng/titles/0-201-82470-1/
More recently, Stan Lippman has written a shorter introductory text aimed at experienced programmers. Here's a review:
http://www.ercb.mv.com/feature/feature.0050.html
Andy Koenig and Barbara Moo's Accelerated C++ is a valuable addition to the ranks of modern C++ primers. It takes a refreshing approach to the use of the standard library, introducing useful programming techniques early and providing many real-world examples. Absolute beginners to programming may find the pace intimidating, however.
http://www.aw.com/cseng/series/indepth/
Bruce Eckel's Thinking in C++ is often recommended in posts to alt.comp.lang.learn.c-c++. The online version is available for download at:
http://www.mindview.net/Books/TICPP/ThinkingInCPP2e.html
For a C++ standard library reference, Nicolai Josuttis' The C++ Standard Library is one of the best.
http://www.josuttis.com/libbook/
Matt Austern's Generic Programming and the STL is also well thought of, although not specifically a standard library reference.
http://www.awlonline.com/product/0,2627,0201309564,00.html
We could go on. As you progress in your studies, you will want to add Scott Meyers and Herb Sutter (amongst others) to your arsenal of authors. The C++ FAQ also contains some recommendations for C++ books.

See also:

http://marshall-cline.home.att.net/cpp-faq-lite/how-to-learn-cpp.html#[26.4]

Back to Contents


6.4 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. Schildt's beautifully clear writing style only makes things worse by causing many "satisfied" learners to recommend his books to other students.

Do take a look at the following scathing articles before deciding to buy a Schildt text.

http://www.lysator.liu.se/c/schildt.html
http://herd.plethora.net/~seebs/c/c_tcr.html
The above reviews are admittedly based on two of Schildt's older books. However, the language they describe has not changed in the intervening period, and several books written at around the same time remain highly regarded.

Back to Contents


7.1 What online tutorials exist for learning C and C++?

We often get questions from students who would prefer to learn from a web page instead of buying a book. Our standard warning - while there is some valuable material out there on the web, there is also an enormous amount of nonsense written about both languages. The trouble is, as a beginner you may not have the ability to tell the difference! For this reason, we usually recommend that you obtain at least one good book to supplement your learning.

One of the best online C language tutorials is Steve Summit's site, where he makes available 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
Ted Jensen's tutorial on pointers and arrays in C can be found at
http://pweb.netcom.com/~tjensen/ptr/cpoint.htm
Tom Torfs has written an excellent, complete tutorial, meant to complement a good introduction to C. It's not primarily intended for the complete beginner to the language, though.
http://members.xoom.com/tomtorfs/cintro.html
There are few, if any, credible tutorials for standard C++ online. Your best bet is a reliable textbook (see 6.3).

Back to Contents


7.2 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.

For beginners to C and C++, Jack Klein has put up an excellent page with tips, suggestions and expanded answers to a number of commonly asked beginners' questions.

http://home.att.net/~jackklein/c/c_main.html
The Comeau Computing web site features several highly informative and useful resource pages, including
http://www.comeaucomputing.com/booklist/
http://www.comeaucomputing.com/faqs/cppfaq.html
http://www.comeaucomputing.com/techtalk/
Jim Fischer maintains a C++ FAQ:
http://www.calpoly.edu/~jfischer/c++faq/
Steve Summit has archived some of his longer and more informative Usenet posts at
http://www.eskimo.com/~scs/readings/index2.html
New posters often request information on file formats. A good resource for this can be found here:
http://www.wotsit.org/
A large C++ link farm is maintained at:
http://www.cetus-links.org/oo_c_plus_plus.html
Questions and answers from Herb Sutter's popular Guru Of The Week series are archived here:
http://www.gotw.ca/
Bjarne Stroustrup's homepage
http://www.research.att.com/~bs/

Back to Contents


8.1 How rude! Why do people keep redirecting me to another group?

Because we don't answer questions like the one you asked. You wanted to know about Windows, right? Or comboboxes. Or serial ports. Or something else that has nothing whatsoever to do with the C or C++ standard languages.

Please don't be offended when someone asks you to post in another group. All they are saying is that there is another resource that would be more appropriate for your question. If you walk into a delicatessen and ask for roofing tiles, the staff will look at you askance and direct you to the nearest building supplies outlet. It's the same principle.

Please read the FAQ of any group prior to posting your query there.

Note: where you see an `*' at the end of a name in the lists that follow, it means "hierarchy". You will find more than one newsgroup beginning with that root name. For example,

comp.os.ms-windows.programmer.*
is a hierarchy containing 10 other groups or sub-hierarchies.

See also:

http://www.slack.net/~shiva/welcome.txt
http://www.borland.com/newsgroups

Back to Contents


8.2 C and C++ language groups

The following newsgroups include the "Big Six" of standard C and C++. Some of the best, smartest programmers in the world read them. You will find that the .moderated versions tend to have less traffic, but are free of spam and off-topic posts. The so-called "signal to noise ratio" is higher, making them excellent resources.

Try searching the archives of these before asking a question on alt.comp.lang.learn.c-c++. Please note that these forums are not always the most appropriate choice for asking absolute beginner questions, like "Why won't hello.c compile?" The comp.std.* groups are moderated, and tend to discuss language features on a rather esoteric level.

C

comp.lang.c
comp.lang.c.moderated
comp.std.c
Discussions on C in other languages include:
de.comp.lang.c
fj.comp.lang.c
fr.comp.lang.c
han.comp.lang.c

C++

comp.lang.c++
comp.lang.c++.moderated
comp.std.c++
Discussions on C++ in other languages include:
de.comp.lang.c++
it.comp.lang.c++
es.comp.lang.c++
han.comp.lang.c++
See also:
8.3 General programming groups
8.4 Compilers and libraries
8.5 Operating systems

Back to Contents


8.3 General programming groups

These newsgroups address programming issues without a particular language focus. They are more appropriate for general programming questions.

Algorithms: comp.programming
Games: alt.games.programming, comp.games.development.programming.algorithms
Graphics: comp.graphics.algorithms
Object oriented programming: comp.object

See also:

http://pauillac.inria.fr/algo/AofA/

Back to Contents


8.4 Compilers and libraries

These newsgroups discuss a particular compiler or development environment - an implementation of C or C++ (or both). They are the place to go when you have a question that does not relate to the language itself, but to facilities provided by the implementation.

In addition, listed below are groups which discuss common libraries in use for various environments.

Both Microsoft and Borland operate their own public servers to facilitate access to their respective newsgroup hierarchies.

Microsoft: msnews.microsoft.com
Borland: forums.inprise.com

Compilers

Borland C++: borland.public.cpp, borland.public.cpp.language
Borland C++Builder: borland.public.cppbuilder, borland.public.cppbuilder.language
CodeWarrior: comp.sys.mac.programmer.codewarrior
DJGPP: comp.os.msdos.djgpp
GCC: gnu.gcc, gnu.gcc.help, gnu.g++.help
LCC: comp.compilers.lcc
Visual C++: microsoft.public.vc.ide_general, microsoft.public.vc.language

Libraries

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
LEDA: comp.lang.c++.leda

Back to Contents


8.5 Operating systems

Amiga: comp.sys.amiga.programmer
DOS: comp.os.msdos.programmer
GNU/Linux: comp.os.linux.development.*
Macintosh: comp.sys.mac.programmer.*
MS Windows: comp.os.ms-windows.programmer.*, microsoft.public.win16.programmer.*,
microsoft.public.win32.programmer.*
OS/2: comp.os.os2.programmer.misc
UNIX: comp.unix.programmer

Back to Contents


9.1 Why doesn't this FAQ cover language issues in more detail?

This is because other better, more comprehensive resources exist for this purpose - in particular, the comp.lang.c and comp.lang.c++ FAQs:

The comp.lang.c FAQ
http://www.eskimo.com/~scs/C-faq/top.html
C++ FAQ lite
http://marshall-cline.home.att.net/cpp-faq-lite/

Back to Contents


Appendix A - Change History

A list of changes covering the revision from "old" FAQ to "new" can be found at http://snurse-l.org/acllc-c++/ChangeLog, or via anonymous FTP at ftp://snurse-l.org/pub/acllc-c++/ChangeLog.

Back to Contents


Appendix B - Contributors

The following people have contributed to this FAQ with helpful comments, suggestions, advice, corrections and constructive criticism, and (in the case of some) for permission to quote from their papers/posts.

Jabari Adisa, Sahan Amarasekera, Mark Brown, Steve Clamage, Jerry Coffin, Greg Comeau, Dann Corbit, Billy Chambless, James Dennett, Dave Dunfield, Cameron Foster, Jim Gewin, Alex Gibson, Stuart Hall, Pablo Halpern, Lars Hecking, Brody Hurst, Jack Klein, Kaz Kylheku, Martijn Lievaart, Daniel Longest, Bernd Luevelsmeyer, Michael McGoldrick, Chris Newton, Dennis Ritchie, Wieland St Bjarne Stroustrup, Dennis Swanson.

Back to Contents


Last modified: Sat Sep 29 11:57:24 EST 2001