C11 standard and support

Earlier this week apple released the Xcode 4.4.1 with more C11 support.

Nice for them, to keep up with Linux which of course supports it much sooner…

in the GCC page (http://gcc.gnu.org/projects/cxx0x.html) you can see which standard is implemented where.

Check your GCC version

To check you own version of GCC use gcc –version from the command line.

What’s new with this standard?

Among other things, the new for loop stands out.

Now, you can execute code like this:

int arr[]={1,3,4,76,2,5};
for(int i:arr)
{
    cout <<i;
}

Which will actually work. This very cool and long wanted feature, with many more (again look at the gcc link) is now part of apple’s Xcode. Yes, you can even use it on the iPhone.

Another new great feature is the introduction of the keyword auto. Which in turn enables you to assign value to a variable without declaring its whole referencing (e.g std::map<string,myobject*>::iterator it can be auto it).

Another feature is the moving constructor. C++ has for a long time copy and assignment constructors. The move constructor enables class to move resources from another class instead of just copy them. Also, new methods introduced to the stl to support this feature.

Compiler options

if you have the right GCC version but you still get an error trying to use this standard, try add this:-std=c++0x to the compiler options.

 

Someone was left behind

Not very surprising – MS is not supporting the C11 standard in Visual Studio 2010. Trying to code this in Visual studio will result in a compiler error.

Update:

MS visual studio 2012, now supports C11.