[Xastir-Dev] Interesting compiler difference
Chuck Byam
cbyam at virginia.edu
Fri Nov 28 09:18:49 EST 2003
On Wednesday 26 November 2003 09:51, Curt Mills wrote:
<< snip, snip >>
> Turns out I did a boo-boo and put a variable declaration a few lines
> down in a block, after some other executable code. Gcc 3.3 didn't
> care and compiled it anyway. The older gcc did. I did a tkdiff
> this morning on that file to see what the differences where.
>
> Anyone else run across this sort of thing?
The compiler treats anything defined inside a codeblock as local to that
block. This can be very handy and the souce of frustration as well. Note
that a codeblock also includes if/do while, etc. This also helps enforce the
"suggestion" that definitions should be made as close to the point of use as
possible.
--
Chuck
int main()
{
int i = 0;
int f = 0;
printf("the value of the first i == %i\n", i);
printf("the value of f == %i\n", f);
{
int i = 1;
printf("the value of the second i == %i and is local to the
codeblock\n", i);
printf("I can still see f though (%i)\n", f);
}
printf("the value of the first i == %i\n", i);
return 0;
}
More information about the Xastir-dev
mailing list