Mail Archives: djgpp/1996/04/06/21:03:42
> >I simply have several question in mind about compilation of C.
> >
> >When I do:
> >int i;
> >
> >i=3+4;
> >
> >Does GCC generate i=7 or i=3+4 ?
> >
> >I suppose the answer is the same for
> >i=0x01 | 0x02 which is equal to i=0x03
> >
> >Again, in:
> >#define FIVE 3+2
> >
> >is it the same, for the compiled program as #define FIVE 5 ?
I tried the following function with gcc -S -g:
int f( int n )
{
return 3 + n + 4;
}
gcc generated something equivallent to 'return 7 + n;'.
If I recall correctly, in The C Language, 1st ed., K&R said that C
compilers almost always(note that I turned the debugging option, -g,
on) do such kind of optimizations. That's why the orders of
sub-expression evalutions in C are unspecified - C compilers are
expected to do so many optimizations.
BTW, if you may use FIVE in contexts such as (3*FIVE), you'd better
write
#define FIVE 3+2
as
#define FIVE (3+2)
Regards,
Wang TianXing
- Raw text -