Fang's Temple of C++
Introduction
"To use C++ over any other managed language is to choose the way of the light-saber over laser pistols."C++ is my weapon of choice -- two-handed, double-edged, and post-increment. I do not do Java -- I do not fear memory management, nor do I depend on graphical user-interface libraries. C suffers horribly from type-unsafety, lacks abstraction, and is practically useless for complex programs -- you might as well write macro-assembly. Within this page you'll find some tidbits, links, and rants on why C++ is right for you.
Compilers
GCC (g++), GNU free (as in speech AND beer) compiler Not a day goes by where I don't use it. (I need a life.) bug farm, weekly bugz Wiki documentation index internals documentation I typically keep my C++ sources compatible across versions 3.3 through 4.2 (current prerelease). 3.3 changes, 3.4 changes, 4.0 changes, 4.1 changes, 4.2 changes, 4.3 changes, 4.4 changes 4.5 changes 4.6 changes C++0x branch page Low-Level Virtual Machine compiler infrastructure clang C and C++ front-end porting to powerpc-darwin8 ICC (icpc), Intel's compiler (free for academic use with registration) ICC for Mac OS X (Intel Macs only) Mac, linux, user's forum XLC++, IBM's commercial compiler (never got my hands on it) Comeau, the most standard-conforming C++ front-end to date (commercial) try it online here online documentation Edison Design Group (EDG) C++ front-end HP C++ -- never tried it OpenWatcom -- free, never tried it DigitalMars -- free, for Windows, never tried it Microsoft Visual C++ -- for windows, never tried it MinGW (Minimalist GNU for Windows) -- free, never tried itRelated Compiler Projects
ROSE for optimizing user-defined abstractions CodePlay multi-core targeting C++ compiler Root5 -- an object-oriented data analysis framework CINT C/C++ Interpreter [appears to be work in progress] Delta a test-case reducing tool, useful for general debugging Elsa Elkhound based C/C++ parser
contains some interesting information on semantics checking in the low-level documentationAnal Retentiveness
I require the following g++ CXXFLAGS for my C++ projects:
-ansi : use latest ISO/ANSI standard and disable GNU extensions
-pedantic-errors : standard violations promoted to errors
-Wold-style-cast : reject C-style "(type)arg" casting
-Woverloaded-virtual : overloaded virtual functions
-Wall : a ton of common warnings
-W : even more warnings
-Wundef : undefined preprocessor macro evaluated
-Wshadow : shadowing names of variables in higher scopes
-Wno-unused-parameter : ignore unused function parameters (for documentation purposes)
-Wpointer-arith : suspicious pointer arithmetic
-Wcast-qual : cast violates const/volatile qualifiers
-Wcast-align : cast causes alignment requirement to increase
-Wconversion : prototype causes conversions to differ
-Werror : promote all warnings to errors These flags work fine for g++, but can cause some minor portability headaches: ICC warnings -- discusses how to disable some ICC warnings that may affect the outcome of crucial configure tests
Bookmarks
References
The People's Toolbox for C++ CppReference.com Wikipedia's Entry on C++ Informit.com -- C++ reference, good articles with examples and explanationsGeneral FAQs
Bjarne Stroustrup's C++ FAQ: (part 1), (part 2: style and technique) -- worth a read from the creator of C++ http://new-brunswick.net/workshop/c++/faq/ -- a general collection of questions and answers http://www.parashift.com/c++-faq-lite/ http://www.faqs.org/faqs/C++-faq/ -- links to collections of FAQs http://www.comeaucomputing.com/techtalk/ -- lengthy C and C++ FAQ another general collection of links more links of interest to C++Standards
THE ISO C++ Standards Committee -- very dry but authoritative reading material Current Standard *DRAFT*, technical report 3126 (PDF) Informit's introduction to C++0xRvalue references (C++0x)
N1337: (2002) initial proposal to add support for move semantics in C++ N1385: argument forwarding problem, related to rvalue references N1690: (2004) proposal to add rvalue reference to C++ language N1770: proposed wording for rvalue references standard N1771: impact of rvalue references on STL -- very positive N2027: (2006) a brief introduction to rvalue references N2118: Rvalue Reference Proposal, Revision 3, by Howard Hinnant, 2006-10-19 Core Issue -- template argument deduction of rvalue references Russell Yanofsky's prototype work on implementing rvalue references in g++ (2005) updated gcc patch, 2007-02-20 updated gcc patch, 2007-04-24 a set of tests and benchmarks demonstrating copy-elision, courtesy of Howard HinnantGuidelines
Various sources on what subsets of the C++ language and style are approved. Google's C++ guidelinesJournals
The C++ SourceNewsgroups
http://www.gotw.ca/resources/clcm.htm -- guidelines for posting to comp.lang.c++.moderatedGrammar
An LALR(1) grammar for C++Python
Python-to-C++ compiler project
Libraries
Know the Standard Template Library, and thou shalt be enlightened. GCC's C++ STL documentation page Boost -- peer-reviewed libraries and more http://www.trumphurst.com/cpplibs/cpplibs.phtml -- a decently updated list of available C++ libraries STLPort -- portable standard libraries (haven't tried it)
Books
Recommended reading and reference list. TODO: add Amazon links. C++ Primer Plus, 3rd Ed. The C++ Programming Language, 3rd Ed., by Bjarne Stroustrup C++ Templates, by David Vandevoorde and Nicolai Josuttis C++ Template Metaprogramming, by David Abrahams and Aleksey Gurtovoy Modern C++ Design, by Andrei Alexandrescu Comeau's C++ reading list
Short Essays
Eventually, I'll fill in this section with some rants. Topics:
Learning C++
Overcoming Fear, Uncertainty, and Doubt.
Teaching C++
Some growing lists: The worst things one can do when teaching C++: 1) Introduce C++ as a more featured extension of C and use all the bad practices that come with C 2) Introduce the STL as "just a bunch of containers" 3) Start by introducing graphical libraries and user-interface libraries 4) Skipping or down-playing the role of "Resource Acquisition is Initialization" Things one *must* teach with C++: 1) Source code organization and management, especially w.r.t. templates 2) The philosophies behind the design of the STL with examples from the STL 3) Distinction between allocators and constructors 4) Orthogonal design principles Bjarne, on teaching students, Aug. 2006 Greg Comeau, on C, C++ teaching/learning, ca. 1999 Q: How would *I* teach C++? Would I teach C++ differently to those coming from different progamming backgrounds? Most likely, with emphasis on unlearning bad practices commonplace to other languages, especially C. Show by example after example, and short motivating exercises. Examples convey ideas more effectively than technical reading passages.
Resource Acquisition Is Initialization
Memory management
Managed languages have their place, but they can also breed sloppy and irresponsible programmers. Rant about naked pointers. Why not garbage collection? Memory Management in C++, Nathan C. Myers, 1993 (old but contains some key ideas) "C++ Memory Management: From Fear to Triumph", by George Belotsky, 2003-05-08
Portability of C++
Links: Short article on C++ regarding 64b-ness Dan Kegel's collection of migration and portability links Apple's notes for migrating from gcc-3.3 to 4.0 -- mostly vendor-independent TODO: post my collection of C++-related autoconf macros here, and to the macro-archive
Value and reference semantics
Links: http://www.goingware.com/tips/parameters/
Functional programming in C++
C++ for performance
"What you don't use, you don't pay for." -- Bjarne Stroustrup C++ was designed with a 'zero-overhead' principle... Abstraction and the Machine, by Bjarne Stroustrup, 2005 (PDF) Why Are You Still Using C?, by James Grenning, 2003 (PDF) The Empty Member C++ Optimization, by Nathan C. Myers, Aug. 1997 Manual optimization techiniques and idioms
Template metaprogramming
Wikipedia entry on Template Metaprogramming
Static global object ordering and lifetime management
Kai C++ tutorial, one solution using a reference-count
Pitfalls
Never call virtual functions during construction or destruction of base class
Concurrency
Standards committee dicusses threads and concurrency for C++0x (artima.com) Technical proposals N1875: C++ Threads, by Lawrence Crowl, 2005-10-03 N1883: Preliminary Threading Library Proposal for TR2, by Kevlin Henney N1907: Multithreading Library Proposal (rev. 1), by Pete Becker, 2005-10-19 N2047: Atmoic Operations Library for C++, by Hans Boehm, 2006-06-24 N2094: Multithreading API, Layered Approach, by Howard Hinnant, 2006-09-09
Standards
Style
Some personal usage patterns and style.Const-correctness
For comprehensibility, and performance. Links: http://www.cprogramming.com/tutorial/const_correctness.html -- a tutorial http://www.possibility.com/Cpp/const.html -- nice explanation, also discusses related topicsForward declarations
Comparisons of C++ vs. other languages
Generics (Templates): C++, C#, Java -- a 3-way comparison The Perils of Java Schools, by Joel Spolsky, 2005-12-29
History, Future, Design and Evolution
Design and Evolution in 2005, Bjarne Stroustrup (PDF)
Interviews about C++
LinuxWorld.com with Bjarne Stroustrup, 2001-02-20 Technology Review with Bjarne: "The problem with programming", 2006-11-28 Technology Review with Bjarne: "More problems with programming", 2006-12-07 Bjarne Stroustrup Expounds on Concepts and the Future of C++, 2009-08-06 And for those of you looking for the *fake* interview with Bjarne here are some links (multiple provided since they tend to decay with time), showing that in spite of my web-page appearances, I do have a sense of humor. peteraiken.net leech.dk
Flaming C++
This page would not be complete without references to why people dislike C++. Bjarne's objective replies to C++ flaming, from newsgroup posting
The End of C++
Reasons why C++ will never die.
[back to Open Source] [back to main]