Related articles |
---|
Strange Behavior With Solaris (Sparc) C Compiler djm52@cornell.edu (Daniel Marques) (2005-05-13) |
Re: Strange Behavior With Solaris (Sparc) C Compiler mayan@sandbridgetech.com (Mayan Moudgill) (2005-05-14) |
Re: Strange Behavior With Solaris (Sparc) C Compiler gah@ugcs.caltech.edu (glen herrmannsfeldt) (2005-05-14) |
Re: Strange Behavior With Solaris (Sparc) C Compiler js@cs.tu-berlin.de (2005-05-14) |
Re: Strange Behavior With Solaris (Sparc) C Compiler djm52@cornell.edu (Daniel Marques) (2005-05-16) |
Re: Strange Behavior With Solaris (Sparc) C Compiler touati@prism.uvsq.fr (TOUATI Sid) (2005-05-20) |
From: | Mayan Moudgill <mayan@sandbridgetech.com> |
Newsgroups: | comp.unix.solaris,comp.compilers |
Date: | 14 May 2005 01:11:56 -0400 |
Organization: | Posted via Supernews, http://www.supernews.com |
References: | 05-05-065 |
Keywords: | C, code |
Posted-Date: | 14 May 2005 01:11:56 EDT |
Daniel Marques wrote:
> Hello. I have a question regarding some behavior I'm
> seeing with the C compiler on Solaris 9 and was hoping someone could
> shed some insight.
>
>
> However, when I compile with the command "cc -c -g -xO0 test.c", nm now
> reports the size of "mother" as 0.
> // test.c
>
> int foo(int i)
> {
>
> static int mother = 98;
> static int father;
>
> if(i & 123)
> mother += 8;
> if(i % 4)
> father += 10 * i;
>
> return mother + father;
> }
The above code is equivalent to
int foo(int i)
{
static int res = 98;
if( (i&123) ) {
if( i%4) {
result += 10*i + 8;
}
else {
result += 8;
}
}
return;
}
[Note that i%4!=0 == (i&3) !=0 => i&123 != 0, so don't have to deal with
separate if( !(i&123) && (i%4) ) case]
It could be the compiler is optimizing away one of the static variables.
Return to the
comp.compilers page.
Search the
comp.compilers archives again.