[Info-vax] decrementing & for loops in C
Johnny Billquist
bqt at update.uu.se
Mon Jan 12 17:37:45 EST 2009
Bill Gunshannon skrev:
> What, you say that's just silly. How about this?
>
> {
> int thrust_reversers, power_level;
>
> { thrust_reversers = 10; power_level = 20; }
> }
>
> Does the order of these two (apparently) equal operations make a difference?
> Can a machine determine that?
To make an even better point. And this is actually going to happen in a C
program, if you check the output, Bill.
{
int i;
i = 10;
i = 20;
printf("i is %d\n", i);
}
Check the resulting code, and you'll notice that the i = 10; statement gets
optimized away. The compiler (optimizer) realize that noone cares about the
first value you assign to i, so it can throw that whole part away.
What the "problem" is here, is that you haven't told C enough for it to realize
that this actually do matter to you.
Johnny
--
Johnny Billquist || "I'm on a bus
|| on a psychedelic trip
email: bqt at softjar.se || Reading murder books
pdp is alive! || tryin' to stay hip" - B. Idol
More information about the Info-vax
mailing list