Union Wierdness on Sparc C Compiler
Greg Kemnitz
kemnitz at postgres.berkeley.edu
Thu Jun 7 11:48:49 AEST 1990
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 at postgres.berkeley.edu | of ULTRIX manuals" :-)
|
| --A friend at DEC Palo Alto in the Quake
More information about the Comp.sys.sun
mailing list