Re: Strange Behavior With Solaris (Sparc) C Compiler

Daniel Marques <djm52@cornell.edu>
16 May 2005 11:16:28 -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: 16 May 2005 11:16:28 -0400
Organization: Cornell University
References: 05-05-065 05-05-076
Keywords: C++, code
Posted-Date: 16 May 2005 11:16:27 EDT

Mayan Moudgill wrote:
>
> 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.


Sorry, I made a mistake in that test code. I was trying specifically to
make a situation where it would be very hard for the compiler to
optimize away one of the vars and meant
if( !(i % 4) )
                 father += 10 * i;




Anyway, the same behavior occurs with the following code, where I
believe the two vars are entirely independent.




int foo(int i, int r, int c)
{


      static int mother = 10;
      static int father;




      if( ! (i % 2) )
          mother += 18 * r;


      if( ! (r % 3) )
          father += 10 * i;


      if( c > 0 )
          return mother;
      else
          return father;


}




Thanks.


Dan


Post a followup to this message

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