🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.help
Article #54250

problem with structure arguments/returns in 1.37.1 on decstation

#54250
From: Luke Tierney
Date: Sat, 22 Dec 1990 19:28
135 lines
3643 bytes
(I attempted to post this earlier but seem to have failed - I
apologize if you get this more than once.)

I have run into a problem involving structure arguments/return values
in gcc 1.37.1 on a DECstation (built using the patches from
foobar.colorado.edu). I'm not sure if this is a problem with gcc in
general, gcc for the decstations, or with our installation. The
program attached below produces the following results on a decstation:

	nokomis% gcc -v
	gcc version 1.37.1 OSF 1.9.2.14 Ultrix Dec Mips Dec 20 1990
	nokomis% gcc gccbug.c -lm
	nokomis% a.out
	(2.730718,0.000000)
	(0.630930,0.000000)
	nokomis% cc gccbug.c -lm
	nokomis% a.out
	(0.630930,0.000000)
	(0.630930,0.000000)

The two lines printed by a.out should produce identical results, so
the cc results are correct. The DECstation is running ULTRIX 4.0 with
version 2.1 of the MIPS compiler set. An ancient version of gcc
installed on a sun 3/160 running SunOS 3.4 handles this code properly:

	sun2% gcc -v
	gcc version 1.31
	sun2% gcc gccbug.c -lm
	sun2% a.out
	(0.630930,0.000000)
	(0.630930,0.000000)
	sun2%

Here is the file gccbug.c:

------------------------------(cut here)---------------------------------------
#include <stdio.h>
#include <math.h>

#ifndef PI
#define PI 3.141592653589793
#endif /* PI */

typedef struct {
  double real, imag;
} Complex;

checkfzero(x)
     double x;
{
  if (x == 0.0) {
    fprintf(stderr, "illegal zero argument\n");
    exit(-1);
  }
}

Complex cart2complex(real, imag)
	double real, imag;
{
  Complex val;
  val.real = real;
  val.imag = imag;
  return(val);
}

Complex polar2complex(mod, phi)
	double mod, phi;
{
  Complex val;
  val.real = mod * cos(phi);
  val.imag = mod * sin(phi);
  return(val);
}

double modulus(c)
	Complex c;
{
  return(sqrt(c.real * c.real + c.imag * c.imag));
}

double phase(c)
	Complex c;
{
  double phi;
  
  if (c.real == 0.0) {
    if (c.imag > 0.0) phi = PI / 2;
    else if (c.imag == 0.0) phi = 0.0;
    else phi = -PI / 2;
  }
  else {
    phi = atan(c.imag / c.real);
    if (c.real < 0.0) {
      if (c.imag > 0.0) phi += PI;
      else if (c.imag < 0.0) phi -= PI;
      else phi = PI;
    }
  }
  return(phi);
}

Complex cdiv(c1, c2)
	Complex c1, c2;
{
  double m1, m2, p1, p2;

  m1 = modulus(c1);
  p1 = phase(c1);
  m2 = modulus(c2);
  p2 = phase(c2);
  checkfzero(m2);
  return(polar2complex(m1 / m2, p1 - p2));
}

Complex clog(c)
	Complex c;
{
  double mod;
  
  mod = modulus(c);
  checkfzero(mod);
  return(cart2complex(log(mod), phase(c)));
}

main()
{
  Complex l1, l2, x;

  x = cdiv(clog(cart2complex(2.0, 0.0)), clog(cart2complex(3.0, 0.0)));
  printf("(%f,%f)\n", x.real, x.imag);
  l1 = clog(cart2complex(2.0, 0.0));
  l2 = clog(cart2complex(3.0, 0.0));
  x = cdiv(l1, l2);
  printf("(%f,%f)\n", x.real, x.imag);
}
Technical Details
Message-ID: <1990Dec22.192837.12449@cs.umn.edu>
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!shelby!msi.umn.edu!cs.umn.edu!umnstat.stat.umn.edu!luke

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 11318c,10b207bdbc57357d,start
X-Google-Attributes: gid11318c,public
X-Google-ArrivalTime: 1990-12-22 12:02:12 PST
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!shelby!msi.umn.edu!cs.umn.edu!umnstat.stat.umn.edu!luke
From: luke@umnstat.stat.umn.edu (Luke Tierney)
Newsgroups: gnu.gcc.help
Subject: problem with structure arguments/returns in 1.37.1 on decstation
Message-ID: <1990Dec22.192837.12449@cs.umn.edu>
Date: 22 Dec 90 19:28:37 GMT
Sender: news@cs.umn.edu (News administrator)
Reply-To: luke@umnstat.stat.umn.edu (Luke Tierney)
Distribution: gnu
Organization: School of Statistics, University of Minnesota
Lines: 135
Nntp-Posting-Host: umnstat.stat.umn.edu