alexande@cs.unc.edu (Geoffrey D. Alexander) (01/13/90)
I have found a possible bug in the order constructor expressions are evaluated
and assigned.  This problem is illustrated by the following program.
====test3.c====================================================================
#include <stdio.h>
typedef struct {
  double real;
  double imaginary;
} complex;
main() {
  complex x;
  complex y;
  x=(complex){1.0,1.0};
  x=(complex){((x).real*(x).real)-((x).imaginary*(x).imaginary),
    ((x).real*(x).imaginary)+((x).real*(x).imaginary)} ;
  fprintf(stdout, "x=%lf", x.real);
  if (x.imaginary>=0.0)  fprintf(stdout,"+");
  fprintf(stdout, "%lfi\n", x.imaginary);
  x=(complex){1.0,1.0};
  y=(complex){((x).real*(x).real)-((x).imaginary*(x).imaginary),
    ((x).real*(x).imaginary)+((x).real*(x).imaginary)} ;
  fprintf(stdout, "y=%lf", y.real);
  if (x.imaginary>=0.0)  fprintf(stdout,"+");
  fprintf(stdout, "%lfi\n", y.imaginary);
  exit(0);
}
===============================================================================
I compiled the program as follows:
   gcc test3.c -O -o test3
I get the following results:
x=0.000000+0.000000i
y=0.000000+2.000000i
The value of y is correct, while the value of x is not.  It seems that the
assignment to x is using the newly computed value of x.real when computing
x.imaginary.  Is this the way it should work?  I would prefer that it use
the original value of x.real in computing x.imaginary.  Any comments from
other gcc users?
Geoff Alexander