🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Eric Jergensen Thu, 10 Sep 1992 03:45
Order of evaluation problem in gcc & g++ on sun4
#1108
Author: 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
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads