Mirror of MacCompanion

macCompanion My AppleSpace Forum Archives Products Services About Us FAQs





Bodelin Technologies - Home of the Proscope USB Digital Microscope

Bodelin Technologies - Home of the Proscope USB Digital Microscope


PowerMax: Sasquatch Approved!

Used Macs & Apple Computers

The Mac Store - Apple Computers in Oregon & Washington

The Mac Store - Apple Computers in Oregon & Washington


IrisInk - Portland & Seattle IT Consultants

IrisInk - Portland & Seattle IT Consultants





Latest Joy of Tech!
Today's Joy of Tech!


Visit StepHouse Networks. Broadband DSL for Apple Users

Legacy Links






Jobs and Careers

Mac 3D



Think Different


According to Hoyle...


C/C++ Language Updates


November 2008

by Jonathan Hoyle



Early last year, I wrote about the upcoming changes in the C++ language According to Hoyle, March 2007.  It has been, by far, my longest article for macCompanion, detailing most of the changes we can expect to see.  (For those interested in a higher level view, you can view my online PowerPoint presentation on the topic.  I will not be repeating that information here, as the great majority of it remains unchanged.  However, I would like to give an update on the subject and provide additional links for those interested in pursuing this further.


C++0x == C++09?


The original specification for C++ was ratified by the ANSI/ISO committees in 1998, and is thus known as C++98.  After a deliberate five years of silence (to assess the state and usage of C++), a Technical Corrigenda was produced with recommendations for bug-fixes in the specification, primarily rewording for clarification.  This update to the language was called C++03 and had almost no real impact on compiler developers.  The only one area that had a potential impact was formalized requirement that the memory allocation for a std::vector<> must be contiguous.  (As this was original the spirit of this container class all along, I know of no compiler vendor which implemented it differently and needed to make this change.)


In 2004, the ISO committee began accepting changes for real language updates, the project name being C++0x, as it was anticipated that this initiative will be finalized sometime in 200x.  Sometime last year, people began referring to C++0x as C++09, as it was obvious that this specification will not be completed prior to 2009.  Unfortunately, there seems to be a realistic chance that this will not be finalized before the decade completes, thus making the working name C++0x possibly out of sync with a 2010 completion.  (Bjarne Stroustrup has made the half-serious suggestion that the x be interpreted hexadecimally, so it would read C++0A if it does not finish in 2009.) 


In any case, the committee members are very much dedicated to finishing this in the 2009 timeframe, so hopefully we won't have to worry about that.


What's In, What's Not


Most all of the most basic changes are certainly in.  These include C99 features (__func__, long long's, variadic macros, and others), Standard Library enhancements (smart pointers, regular expressions, arrays, tuples, etc.), and in-class initializers.  Also making the cut are delegating and inheriting constructors, nullptr, auto & decltype, rvalues references and concepts.  Unfortunately, much less of the threading constructs will be found in C++09 aside from thread local storage.  Some of the mathematical additions are also being held off for this release.


For a more detailed analysis of features being included (as of August 2008), read Bjarne Stroustrup's interview with entitled The State of the Language.


Forgetting to Take Out the Garbage


The biggest item not making it in C++0x is Garbage Collection.  Although this is still on tap for a future rev of the C++ standard, it is very disappointing that this one is missed out.  One of the key benefits of newer C++ like languages (such as Java and C#) are their built-in garbage collection capabilities.  Older languages such as Objective-C are being updated to include this feature, just so they can stay relevant.  Without GC in C++0x, there is the risk that there will not be a C++1x ... or if there is, it will no longer be relevant.


For the C++ programmer wishing to use pointers in a modern way, the new smart pointer shared_ptr<> (borrowed from the Boost framework) should be an adequate substitution.  Thus instead of allocating a heap-based class in the tradition way:


    ObjectType  *myObjectPtr = new ObjectType;


you should declare it as follows:


    shared_ptr<ObjectType>  myObjectPtr = new ObjectType;


By doing so, myObjectPtr is now "smart" and can dispose of itself when it is no longer needed.


What About C?


Long before the advent of C++, the C Language reigned supreme.  Particularly as the 1980's progressed, C's popularity ballooned, and it quickly became the lingua franca of programming languages.  Unfortunately, competing C compilers each had differing implementations, making it difficult for programmers to migrate from one C development environment to another.  As the need for standardization grew, the ANSI committee took on the task of defining a single specification for the language, and ratified ANSI C in 1989.


The ISO committee ratified this standard for international use in 1990.  By the mid-1990s, it was agreed that an update to the language ought to be considered, and the C9x project was under way, with its final ratification as C99 by decade's end (see an online PowerPoint presentation overview of C99.


However, adoption of C99 has been relatively slow, unlike the strong developer embracings of C90 and C++98.  Much of this has to do with developer focus shifting away from C toward C++.  Just as the 1980's was the decade for C, the 1990's was the decade for C++.  C++ was marketed to C developers as "a better C" anyway.  Many compiler vendors simply stopped shipping separate C and C++ products, simply delivering C++ (as it is essentially a superset of C). 


Since many of the changes in C99 are simply adopting features of C++ (including new style comments, intermixing declarations and statements, inline functions, bool type, etc.), these "new" features weren't all that new at all.  The worst part of it all involves C99 changes which introduce strict incompatibilities with C++, such as its complex type, and its clog macro (in C++ it is an iostream global like cout, whereas in C99 it is the complex logarithm function).  For this reason C99 has not enjoyed the mindshare C90 and C++98 had. 


Although most C compilers today have the majority of C99 features available to you, they are not typically well advertised.  Some openly question the continued need for C in a world dominated by newer languages.


Despite this, the ISO C committee is already underway its investigation of changes for a new version of the C language.  It is called the C1x project, and it is very early on in the process. The first draft of the C1x spec has been released this past August. The current plan is for C1x ratification in 2012, but I am inclined to think will take a bit longer than that to come up with something more compelling.


What Will Come of C++0x?


Many in the development community are concerned that C++09 will receive only the same lukewarm response that C99 had.  The parallels between C++09 and C99 are rather obvious.  Both are second generation updates coming 10 years after their primary (and extremely popular) ISO ratifications.  Both first generations were ratified when each language was considered dominant in the industry, whilst both updates come at a time where newer languages have evolved and are taking away mindshare.  With Java, C#, Ruby and others on the upswing, will C++09 offer anything relevant?  The answer to this will evident only with time.


More Information


The Wikipedia entry for C++0x is also an excellent resource.  To get direct information straight from the horse's mouth, view a video of Bjarne Stroustrup's presentation of C++0x to the University of Waterloo.


Coming Up Next Month:  The Top 10 Mac Fiascos!  See you in 30!


Other According to Hoyle columns