How to disable GNU extension in Code::Blocks?

Dear all:

I am using Code::Blocks 12.11 on Ubuntu. Since Code::blocks uses GNU compiler which has language extension, how can I disable this feature? For example, with strict C/C++ syntax, when we (statically) define an array, we have to use a fixed number as the array size. However, with GNU extension, we do not need to follow this rule.

I want to disable this GNU extension so that my code will follow the "pure" C/C++ standard.

Thanks in advance.
Look under the compiler options.
There should be a flag somewhere that has -std=c++xx (where xx is some number, e.g. 98 or 0x or 11).

Turn on one of those.
(I'd recommend the -std=c++11 one unless you have a reason (e.g. your professor/boss telling you so) not to use C++11.)

If you haven't already, I'd also make sure that at least -Wall and -pedantic are checked as well. That way, even if you are using GNU extensions, you should get at least a warning about it.
long double main, thanks for your reply. I checked what you have suggested, but the compiler does not generate the warning I'm expecting.

Below is a simple test code (in C).

1
2
3
4
5
6
7
8
9
#include <stdio.h>

int main(void)
{
    size_t SIZE = 10;
    int arr[SIZE];

    return 0;
}


Here are the warnings.
1
2
3
warning: command line option '-std=c++11' is valid for C++/ObjC++
         but not for C (enabled by default);
warning: unused variable 'arr'


I want to see an error or warning saying that the variable-sized array cannot be defined or something like this.

How can I do this?

BTW, I also enabled "-std=GNU99" in Compiler Settings -> Other Options to follow C99 Standard.

EDIT: I test a C++ code, it does give me the warning. But how come there's no warning for this C code? Do I need to set up something for compiling C program in Code::Blocks?
Last edited on
For C (gcc), use these compiler options: -std=c99 -Wall -Wextra -pedantic-errors

For C++ (g++), use these: -std=c++11 -Wall -Wextra -pedantic-errors
@JLBorges

In Code::Blocks, I have to use "-std=gnu99" to follow C99 standard. "-std=c99" does not work.

But even I set "-std=gnu99", and check -Wall -Wextra -pedantic-errors, still there's no warnings or error messages...

However, when I set "-std=c99", the error message pops up: "ISO C90 forbids variable length arr". This is what I want to see. But this is for C90 rather than C99.

How can I follow C99 and still get warnings or error messages?

Thanks.
Are you using an old version of GCC?

Current versions do support the -std=c99 option.
Perhaps you could consider upgrading to a more recent release of GCC.
Topic archived. No new replies allowed.