🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.bug
Article #2828

Possible bug in constructor expression assignment

#2828
From: Geoffrey D. Alexander
Date: Fri, 12 Jan 1990 17:14
46 lines
1952 bytes
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
Technical Details
Message-ID: <9001121714.AA22008@dopey.cs.unc.edu>
Path: arc1-ca.pugleaf.net!utzoo!telly!attcan!uunet!bu.edu!bu-cs!snorkelwacker!apple!usc!zaphod.mps.ohio-state.edu!tut.cis.ohio-state.edu!cs.unc.edu!alexande

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!telly!attcan!uunet!bu.edu!bu-cs!snorkelwacker!apple!usc!zaphod.mps.ohio-state.edu!tut.cis.ohio-state.edu!cs.unc.edu!alexande
From: alexande@cs.unc.edu (Geoffrey D. Alexander)
Newsgroups: gnu.gcc.bug
Subject: Possible bug in constructor expression assignment
Message-ID: <9001121714.AA22008@dopey.cs.unc.edu>
Date: 12 Jan 90 17:14:02 GMT
Sender: news@tut.cis.ohio-state.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 46