GNU89 mixed declarations and initial cycle declarations

The default C dialect for GCC and ICC is GNU89. GNU89 allows mixed declarations like

int i; i = 0; int j; 

I assumed (incorrectly) from a number of other posts in SO, like C: for the initial declaration of an int loop , which meant that I could do

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

with GNU89, but when I do this, I get

 error: 'for' loop initial declarations are only allowed in C99 mode 

Apparently, mixed declarations and initial cycle declarations are not the same thing (i.e., do not mean the other).

If I had only one, I would prefer to have initial loop declarations. Of course, I could use GNU99, but that is not the point. GNU89 is used by default, and it already violates some C89 rules (it also allows the use of BCPL / C ++ style comments). Is there any fundamental reason why mixed declarations are allowed, but are not initial cycle declarations?

+3
c gcc c99 c89
Apr 22 '14 at 20:47
source share
1 answer

Mixed declarations and declarations precede C89 in other languages ​​(for example, Algol 68) and are a common extension among several C89 compilers (not MSCV).

Declaring a counter variable in a for statement, on the other hand, came in C in C ++ 98, and as far as I know, the C89 compiler found it useful enough to add it as a C89 extension.

+5
Apr 22 '14 at 21:09
source share



All Articles