This is the mail archive of the
mailing list for the GCC project.
Re: Declaring automatic variables inside a while loop
- From: Jim Wilson <wilson at specifixinc dot com>
- To: Swaminathan Venkatakrishnaprasad <vswami at agere dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: Tue, 20 Jan 2004 23:24:58 -0800
- Subject: Re: Declaring automatic variables inside a while loop
- References: <email@example.com>
Swaminathan Venkatakrishnaprasad wrote:
Could you please let me know if it is
valid to declare an automatic variable
inside a for loop.
This has always been legal. The loop body is just a compound statement,
same as a function body.
If yes, is it also allowed
in ANSI standard (could you please refer
me to the sec #).
3.6.2, Compound Statement or Block, in the 1989 ANSI C standard.
Also, in the above example would
the number of iterations contribute anything to the stack
size since an automatic variable is declared
inside the while loop??
No. The variable is allocated only once.
By the way, in your example, you are setting the loop iterator (i) to an
uninitialized local (j) which isn't going to work.
Jim Wilson, GNU Tools Support, http://www.SpecifixInc.com