How to enable c99 and c11 on gcc?

When I compile the following code it gives compilation error that

 error: ‘for’ loop initial declarations are only allowed in C99 mode for(int i = 0; i < 5; i++)

and to compile your code use this option :

 note: use option -std=c99 or -std=gnu99 to compile your code

Now my question is this how to use the above option and enable c99 and c11?

0

1 Answer

As conveyed in the error message, you should compile the code using -std=c99 or -std=gnu99. So, for example, your file is filename.c, then compile using:

gcc -std=c99 filename.c

which will produce a binary a.out if there are no more errors. If you don't want to use this option, you can declare i before the for loop as follows:

int i;
for(i = 0; i < 5; i++)

and compile it using:

gcc filename.c

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like