Mail Archives: djgpp/1997/01/21/02:39:50
Michael Phelps <morphine AT hops DOT cs DOT jhu DOT edu> wrote:
>On Sat, 18 Jan 1997, Daniel Boyer wrote:
>
>> Ok, can somebody please tell me what is wrong with this line of code:
>>
>> for(char SIX = 'a'; SIX < '}'; SIX++)
>
>It looks like you're trying to declare a variable within the for
>statement. Change the file extension to ".cc" and compile it with gxx to
>use C++, which allows such constructs. I don't think C allows this
>(though I could be wrong, and I know it _does_ allow declaring variables
>within a "block").
No, Michael, you are right. ANSI C lets you define variables *only* in
the beginning of a block, before all operators. IE, will be right:
char SIX;
for(SIX = 'a'; SIX < '}'; SIX++)
{
...
}
But completly wrong (for ANSI C, not for C++):
for(char SIX = 'a'; SIX < '}'; SIX++)
{
...
}
But it's all right with something like:
char SIX;
for(char SIX = 'a'; SIX < '}'; SIX++)
{
...
}
{
int SEVEN;
}
because SEVEN was defined in a beginning of the block, limited with brackets,
no metter, thet "for" statement is plased before.
CU, AsH
- Raw text -