Path: utzoo!attcan!uunet!aplcen!samsung!cs.utexas.edu!rice!sun-spots-request From: kemnitz@postgres.berkeley.edu (Greg Kemnitz) Newsgroups: comp.sys.sun Subject: Union Wierdness on Sparc C Compiler Keywords: Software Message-ID: <8618@brazos.Rice.edu> Date: 7 Jun 90 01:48:49 GMT Sender: root@rice.edu Organization: Sun-Spots Lines: 44 Approved: Sun-Spots@rice.edu X-Sun-Spots-Digest: Volume 9, Issue 201, message 9 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