Telling the compiler which version of the language you are using is essential because it improves the portability of your code at very little expense. Additionally, in safety and mission-critical applications, you must verify that the compiler complies with a specific language version using a standardized test suite.
The language acts as an interface between you and the machine. You may well be forgiven for thinking that the C and C++ languages are so well defined by their ISO language specifications that there can be no misunderstanding. Unfortunately, reality has it otherwise.
There are multiple versions of the C and C++ language specifications, starting with ANSI C89 for C and ISO C++ 1998 for C++, right through to C18 and C++20. If you do not tell your compiler which version of the language you are using, it may attempt to comply with any of them or, more likely, none of them. Therefore, it is essential to tell the compiler which version of the language it should abide by. For Clang and GCC, that option is -std=<version>. For example: -std=c11. Other compilers have similar options.
While we are at it, here is another critical language option: -pedantic-errors. In Clang and GCC, this option turns off language extensions. Once again, you’ll find a similar option in other compilers. Turning off language extensions also improves code portability and compiler compliance. Although language extensions can look useful, they are often not well-defined and are frequently untested. After 30 years, for example, Linux is still bound to the GCC compiler because of language extensions that looked useful back in 1991.
In mission, security, and safety-critical systems, it is important that you define the specification of your interfaces and, most certainly, that of the programming language that you use. In SuperTest, some configurations have as many as ten lines of options to make GCC and Clang as compliant as possible. However, the two options above will already give you great results.
Dr. Marcel Beemster, CTO
Subscribe to our monthly blog!