Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Set CodeBlocks for ISO C99 mode only

How can I set my compiler to allow compiling only the code which was written in ISO C99 mode?

I have done the following:

Project -> Properties -> Project’s build options -> Here I selected ISO C99

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

However, when I try to compile:

#include <stdio.h>
int main()
{
    for(int i=0;i<5;i++)
        printf("%d",i);
    return 0;
}

I don’t get any warnings,
I should get warning:

for loop declarations are not allowed in C99 mode.

Could you help me fix this?

>Solution :

C99 does support declarations of variable inside the iteration statement of a for-loop. See 6.8.5 of the C99 standard for reference:

iteration-statement:

while ( expression ) statement

do statement while ( expression ) ;

for ( expressionopt ; expressionopt ; expressionopt ) statement

for ( declaration expression opt ; expressionopt ) statement

6.8.5.3 further clarifies the scoping of variables declared in a for-loop iteration clause:

The statement

for ( clause-1 ; expression-2 ; expression-3 ) statement

behaves as follows: The expression expression-2 is the controlling expression that is
evaluated before each execution of the loop body. The expression expression-3 is
evaluated as a void expression after each execution of the loop body. If clause-1 is a
declaration, the scope of any variables it declares is the remainder of the declaration and
the entire loop, including the other two expressions
; it is reached in the order of execution
before the first evaluation of the controlling expression. If clause-1 is an expression, it is
evaluated as a void expression before the first evaluation of the controlling expression.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading