for ( int iIdx = 0; iIdx < argc; ++iIdx )
_tprintf( TEXT( "Arg %d: %s\n" ), iIdx, argv[ iIdx ] );
_tprintf( TEXT( "\n" ) );
Is this valid in C? Because I get an error when I tr开发者_JAVA百科y to compile it, if I remove the int from the initializer section of the for loop, it compiles fine...
It is not valid in C before C99.
In C89/90 and earlier, declarations need to be at the start of each block. You can't interleave declarations and normal code.
A declaration inside the for
does not count as being at the start of a block.
Yes. Microsoft's C compiler (cl
) does not support modern C (C99). For loop initializers like that are new in C99.
精彩评论