08-22-2002
9,926,
461
Join Date: Aug 2001
Last Activity: 26 February 2016, 12:31 PM EST
Location: Ashburn, Virginia
Posts: 9,926
Thanks Given: 63
Thanked 461 Times in 270 Posts
Actually, you are misbehaving, not the compiler. When you violate the rules of a language any behavior by the compiler becomes legal. As for why this particular result happens, code like:
const int x = 10;
printf("%p %d \n", &x, x);
can be rewritten by the compiler as something like:
const int x = 10;
printf("%p 10 \n", &x);
Whether or not this happens is up the compiler. Most compilers have options to control optimizations. By fiddling with these options you may be able to induce both behaviors from both compilers. Or maybe not. "Garbage in, garbage out" applys heavily to compilers.