Skip to content

section3_c_standard

Fábio Gaspar edited this page Jan 11, 2019 · 1 revision

C language standards

The C language is defined by an international standard. This ensures that whatever tools you use to compile C code you should get the same results and if a feature is standard you should be able to use it across different systems, as far as the compiler you use is up to date and supports the specific standard you need.

From time to time, new standards are defined. The latest revision was published on 8th December, 2011 (referred as C11 standard). These revisions might bring new functionalities to the language and new rules. For example, the C11 standard introduced

... type generic macros, anonymous structures, improved Unicode support, atomic operations, multi-threading, and bounds-checked functions.

However, new standards might also deprecate and make some old practices obsolte, which means if you attempt to compile the same piece of code targetting different standards if might fail in one of them and work in other, i.e., if from C89 to C99 a feature is deprecated, then using that feature in a C99 compiler will result in a failed compilation. The reverse situation also holds. C11 introduces new libraries for threads. If you attempt to compile a program that uses threads and target it to C99 it will fail.

If you are getting started with C, you souldn't need to worry much about this. But if you plan to develop larger projects where portability matters, you will have to take the decision of which standard you need and make sure there's a compiler supporting that standard for every platform (embeded systems, Windows, Linux, etc.).

In this workshop the code is conformant to C89, which is widely supported. However that's not the case for C99 and C11 where some compilers don't support new features at all or only support partially. Fortunately, there are at least two compilers wich support the latest standards fully: gcc and clang. If they support the platform you are targetting is another question.