From the author of

From the author of

The 2011 Christmas present for all of us from WG14 was a new version of the C standard. In my case, receiving this gift meant that I got to spend some time over the Christmas holidays implementing parts of it in Clang and FreeBSD. C11 includes several new featuresand it has some interesting omissions. In this article, we'll take a look at what's changed.

One item that has been on my wish list for a couple of years failed to make it into the new standard: support for vectors. GCC and Clang already have extensions to C that support vector types and will generate code for things like AltiVec or SSE from those vector types. In the case of Clang, vector types are used in the OpenCL mode for a lot of the standard OpenCL C types.

I suspect that the existence of OpenCL C is a major reason why vectors didn't make it into the new specification. Using OpenCL C makes it easy to write number-crunching code that runs on CPUs and GPUs. This dialect of C also includes a lot of extra numerical functions that wouldn't be appropriate in a general-purpose C implementation.

OpenCL C also adapts more quickly than C. New versions of the C standard are expected to last about a decade. In that amount of time, CPUs have become faster, and symmetric multiprocessing has gone from something for high-end workstations to something that happens even in mobile phones, but the overall programmer model is quite similar. In the same timeframe, GPUs have gone from being barely programmable to being general-purpose processors.

C++ Compatibility

The previous version of the C specification was released a year after an update to the C++ specification and introduced a lot of incompatibilities. For example, C99 introduced the long long type for 64-bit values, which isn't supported in standard C++. Additionally, C99 introduced support for variable-length arrays (VLAs), but they aren't supported in C++. (For non-POD types, VLAs are astonishingly difficult to get right.)

With C11, variable-length arrays are optionalprobably a good thing, as they're almost impossible to use safely. C++11 introduced most of the features of C99, and this time the C and C++ standards committees have worked together to try to ensure that most of the new stuff in C will also work in C++.