Search

0.10 — Configuring your compiler: Compiler extensions

The C++ standard defines rules about how programs should behave in specific circumstances. And in most cases, compilers will follow these rules. However, many compilers implement their own changes to the language, often to enhance compatibility with other versions of the language (e.g. C99), or for historical reasons. These compiler-specific behaviors are called compiler extensions.

Writing a program that makes use of a compiler extension allows you to write programs that are incompatible with the C++ standard. Programs using non-standard extensions generally will not compile on other compilers (that don’t support those same extensions), or if they do, they may not run correctly.

Frustratingly, compiler extensions are often enabled by default. This is particularly damaging for new learners, who may think some behavior that works is part of official C++ standard, when in fact their compiler is simply over-permissive.

Because compiler extensions are never necessary, and cause your programs to be non-compliant with C++ standards, we recommend turning compiler extensions off.

Best practice

Disable compiler extensions to ensure your programs (and coding practices) remain compliant with C++ standards and will work on any system.

Disabling compiler extensions

For Visual Studio users

To disable compiler extensions, right click on your project name in the Solution Explorer window, then choose Properties:

Solution Explorer Properties

From the Project dialog, first make sure the Configuration field is set to All Configurations.

Then, click C/C++ > Language tab, and set Disable Language Extensions to Yes (/Za).

Disable Language Extensions

For Code::Blocks users

Disable compiler extensions via Settings menu > Compiler > Compiler flags tab, then find and check the -pedantic-errors option.

Disable Language Extensions

For GCC/G++ users

You can disable compiler extensions by adding the -pedantic-errors flag to the compile command line.

Related content

Xcode users can refer to Rory’s comment, who kindly provided instructions.

A reminder

These settings are applied on a per-project basis. You need to set them every time you create a new project, or create a template project with those settings once and use that to create new projects.


0.11 -- Configuring your compiler: Warning and error levels
Index
0.9 -- Configuring your compiler: Build configurations

80 comments to 0.10 — Configuring your compiler: Compiler extensions

  • Emmanuel

    Does CLion have these compiler extensions? If so, how do I disable them? I have tried googling by the way to no avail.

  • Manuel Calzadillas

    Very important lesson, even do I believe that not everyone give it the importance it deserve.
    Keep going guys, The tutorial is almost over :)

    • Zelaya

      Got a problem here. Disabling Language extensions make Visual not to compile a code that has #include <Windows.h>
      Any fix or workaround for that?

      • Tom

        Instead of #include <Windows.h> use #include <stdlib.h>, I think (I'm also a noob) windows.h is specific to windows hence why after disabling the extentions it doesen't work.

  • Amazing tutorial to follow, I appreciate the hard work you guys do!  I saw this today and thought it was a very cool for anyone interested in a C++ GB emulator for Switch ( I take no credit for the project ) it’s easy to follow and very in line with the stuff here
    https://github.com/Dooskington/GameLad/wiki
    Stay safe everyone!!

  • Fred

    Hi there, is there something to change from the default settings of Rider (for Unreal Engine) to disable compiler extensions?

  • Ylva

    I have a problem. I could not open those Project Properties and then I figured out that my project was just not built properly: there was no .exe or .sln file. And it was not seen by the Property Manager accordingly. But I bult it a few times and I don't know what's wrong. If anyone knows, please, help.

  • Kevin Muhuri

    The settings from sections 0.10 to 0.12 are not project specific in Code::Blocks. I set them for one project and found the same settings in other projects. So that means Global Compiler Settings.

  • Matteo

    cmake configuration (as well as CLion one) would be in order here :)

  • will

    The drop list where I am supposed to select All Configurations is grayed out so I can't select anything?
    how do I ungray it?

  • Ahmed Sersawy

    thanks for your great effort

  • Jenifer

    How can we know if any particular topic gets updated?If i come back after a while i see lot topics get updated,would like to catch up on updates!!

Leave a Comment

Put all code inside code tags: [code]your code here[/code]