www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/04/06/21:03:42

Message-ID: <3166A608.33A@public1.guangzhou.gd.cn>
Date: Sun, 07 Apr 1996 01:12:40 +0800
From: Wang TianXing <gztxwang AT public1 DOT guangzhou DOT gd DOT cn>
Organization: No Organization
MIME-Version: 1.0
To: DJGPP <djgpp AT delorie DOT com>
Subject: Re: C Question
References: <9604051057 DOT AA52478 AT ibm1 DOT cicrp DOT jussieu DOT fr> <4k34l7$b4k AT news DOT cea DOT fr>

> >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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019