Strange Behavior With Solaris (Sparc) C Compiler

Daniel Marques <djm52@cornell.edu>
13 May 2005 18:00:24 -0400

          From comp.compilers

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)
| List of all articles for this month |

From: Daniel Marques <djm52@cornell.edu>
Newsgroups: comp.unix.solaris,comp.compilers
Date: 13 May 2005 18:00:24 -0400
Organization: Cornell University
Keywords: code, linker, question

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.




$ uname -a
SunOS *.*.* 5.9 Generic_117171-14 sun4u sparc SUNW,Sun-Fire-V210 Solaris


$ cc -V
cc: Sun C 5.5 Patch 112760-16 2005/01/25






When I compile the file test.c (pasted below) with the command "cc -c -g
test.c" and then run "nm test.o" I see, as expected, that each of the
static locals inside of the function have a size of 4:


[Index] Value Size Type Bind Other Shndx Name


[7] | 0| 4|OBJT |GLOB |0 |4
|$XBnBGVA8JvgCGyJ.foo.father


[8] | 0| 4|OBJT |GLOB |0 |3
|$XBnBGVA8JvgCGyJ.foo.mother




However, when I compile with the command "cc -c -g -xO0 test.c", nm now
reports the size of "mother" as 0.


[Index] Value Size Type Bind Other Shndx Name


[15] | 0| 4|OBJT |GLOB |0 |3
|$XBnBGVAGPvgCGxL.foo.father


[14] | 0| 0|OBJT |GLOB |0 |4
|$XBnBGVAGPvgCGxL.foo.mother




Any explanation as to what I am seeing?




Thanks.


Dan






// 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;
}


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.