🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.bug
Article #1108

Order of evaluation problem in gcc & g++ on sun4

#1108
From: Eric Jergensen
Date: Thu, 10 Sep 1992 03:45
39 lines
1365 bytes
For gcc-2.2.2 (compiled w/ CFLAGS='-g -O', default sun4 configuration) on a
sparc, the program:
int main(void)
  {
  float a1[4] = { 1, 2, 3, 4 },
        a2[4] = { 1, 2, 3, 4 };
  float * ptr = a1;
  int i;
  for (i = 0; i < 3; i++)
    {
    *ptr++ = *ptr + 1;
    a2[i] += 1;
    printf("a1[%i] = %g, a2[%i] = %g\n", i, a1[i], i, a2[i]);
    }
  return 0;
  }

produces:
a1[0] = 3, a2[0] = 2
a1[1] = 4, a2[1] = 3
a1[2] = 5, a2[2] = 4

instead of:
a1[0] = 2, a2[0] = 2
a1[1] = 3, a2[1] = 3
a1[2] = 4, a2[2] = 4

The command line used to compile this as C code:
gcc -o testinc -x c testinc.cxx

The command line used to compile this as C++ code:
gcc -o testinc testinc.cxx

BOTH ways of compiling produce code that gives the bad results.

Other compilers (and even gcc-2.2.2 on 3b2) produce code that gives the
intended output.

Eric Jergensen
Technical Details
Message-ID: <9209100345.AA00801@okcforum.osrhe.uoknor.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!sun-barr!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!okcforum.osrhe.uoknor.edu!gej

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!sun-barr!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!okcforum.osrhe.uoknor.edu!gej
From: gej@okcforum.osrhe.uoknor.edu (Eric Jergensen)
Newsgroups: gnu.gcc.bug
Subject: Order of evaluation problem in gcc & g++ on sun4
Message-ID: <9209100345.AA00801@okcforum.osrhe.uoknor.edu>
Date: 10 Sep 92 03:45:15 GMT
Sender: gnulists@ai.mit.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 39
Approved: bug-gcc@prep.ai.mit.edu