Question

The last time I heavily used C++ was years ago, and it was strictly done on the Windows platform. Specifically, I used Microsoft Visual Studio as my IDE and developed some habitual patterns to use Microsoft's C++ version. For example, I used void main() instead of the standard int main().

Now, I am taking a class where it is required to develop programs to be ANSI C++ compliant and the code will be compiled using g++. I quickly learned that system ( "PAUSE" ) does not work in g++ and is probably a Microsoft thing.

Does anyone know of any good resources ( sites, tutorials, books ) where I can learn what more to be better ANSI C++ complaint?

Thank you.

Was it helpful?

Solution

I would highly recommend these two:

  • comp.lang.c++ Usenet newsgroup. If you can get hold of a good Usenet service provider, and use a news reader, you should be able to get rid of the spam. I use eternal-september.org, and like it a lot.
  • Read the C++ FAQ. It has a lot of great information.

Granted, they both are not terribly great if you want a tutorial introduction to C++, but looks like you already know some C++, and need to learn more, and correct bad habits. From my personal experience, the above two are highly useful in doing exactly that.

About comp.lang.c++, make sure you fully read their FAQ and lurk there a while before posting. The same applies to stackoverflow of course, although lurking may not be necessary here.

Using g++, compile your programs with g++ -ansi -pedantic -Wall -Wextra -Weffc++, and make sure you understand all the warnings. I use:

g++ -Wextra -Wall -Weffc++ -ansi -pedantic -Woverloaded-virtual \
-Wcast-align -Wpointer-arith

OTHER TIPS

If you are using g++, then compile with the -pedantic and -std=c++98 flags. The only standard for ANSI C++ is really the ISO Standard document, which cannot be recommended to a beginner. You are mistaken about system("PAUSE"), by the way - system() is part of ANSI C++ - it's parameter is not standardised, however.

Most C++ books will be platform agnostic (of course unless they are made specifically for Visual C++). Here are some good books that are recommended by the pros on ##C++

GCC will do a good job of telling you when your code is not ISO C++ compliant (not that it is an ISO standard, not an ANSI standard). Set the warning options -Werror -Wall, and simply fix all warnings; you soon get out of non-compliant habits and ger fewer and fewer warnings.

There are plenty of good tutorials gcc, has a flag that will make sure the code is ANSI C compliant too, gcc -ansi -Wall -fsyntax-only -pedantic

* Wall - turn on all errors
* ansi - use strict ANSI C specification
* fsyntax-only - only checks syntax
* pedantic - reject violations

Per, comments In addition you can use * -Wextra to turn on a few extra warnings,

update thanks for update on capitalization., and mention of -pedantic

Lots of gcc fans.

The important flags to compile with under Visual Studio to be as strict as possible are:

cl /Za /W4 ...rest of command...

/Za disables Microsoft specific extensions and /W4 is the highest warning level (except /Wall, which complains about ridiculous things).

I'd also recommend you use a modern version of Visual Studio - old versions (VC6) were ridiculously non-conformant, and Microsoft officially pretends they never existed at this point.

I would recommend.

websites:

books:

  • effective C++
  • effective stl
  • modern c++ design
  • template metaprogramming

talking / listening to experts and understanding what they have to say and why.

C++ Primer (4th Ed) appears to be the best beginner book these days as it takes a modern approach and teaches all the important parts of the language. Accelerated C++ is another book often recommended by professionals and it serves as a good introduction, but I wouldn't recommend buying it anymore because C++ Primer nicely replaces it and covers the language better.

Note: C++ Primer Plus (which is a rather bad book) has nothing to do with C++ Primer.

Stroustrup's The C++ Programming Language always needs to be mentioned, of course, because it is written by the father of the language. Many people find it enlightening, but I personally would not recommend it for learning the language.

All the books I mentioned only describe the ISO standard with no non-standard extensions. The programs in these books should work with any C++ compiler.

I like visiting www.cplusplus.com whenever I have a doubt, specially about the standard C++ library.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top