[comp.sys.sun] Union Wierdness on Sparc C Compiler

kemnitz@postgres.berkeley.edu (Greg Kemnitz) (06/07/90)

I am not sure if this is a *bug*, but it sure behaves strangely...  If you
compile the following program on a Sparcstation or Sun 4, you will get 

foo: a is -14249818

(or something similar).  If you compile it on practically anything else,
(ie, DECstation, Sun 3, Sequent, Vax) you get 

foo: a is 22

Using GCC works somewhat better, but you still have to special case any
system calls with union arguments (ie, semctl) to have an address of in
front of them.  Yeah, I know this is not good code, but when you have
170,000 lines of code which assumes that four byte unions are passed by
value, you abandon philosophy for the hope of getting it to work.

typedef union {
	long	value;
} Datum;

main()

{
	Datum datum;

	datum.value = 22;

	foo(datum);

}

foo(a)

char *a;

{
	printf("foo: a is %d\n", a);
}

Greg Kemnitz                  |      "I ran out of the room - I
Postgres Chief Programmer     |      didn't want to be killed by a pile
kemnitz@postgres.berkeley.edu |      of ULTRIX manuals" :-)
                              |
                              |      --A friend at DEC Palo Alto in the Quake

wsd@cs.brown.edu (Wm. Scott `Spot' Draves) (06/08/90)

In article <8618@brazos.Rice.edu> kemnitz@postgres.berkeley.edu (Greg Kemnitz) writes:

   I am not sure if this is a *bug*, but it sure behaves strangely...  If you
   compile the following program on a Sparcstation or Sun 4, you will get 

   foo: a is -14249818

   (or something similar).  If you compile it on practically anything else,
   (ie, DECstation, Sun 3, Sequent, Vax) you get 

   foo: a is 22

This is because unions are passed by reference (pointer).  The program is,
of course, to blame.  try linting it, then shoot the authors of that 170k
line program.

Scott Draves		Space... The Final Frontier
wsd@cs.brown.edu
uunet!brunix!wsd