Path: utzoo!mnetor!uunet!husc6!bloom-beacon!gatech!purdue!umd5!brl-adm!adm!bzs%bu-cs.bu.edu@bu-it.BU.EDU From: bzs%bu-cs.bu.edu@bu-it.BU.EDU (Barry Shein) Newsgroups: comp.unix.wizards Subject: casting to float without converting to float? Message-ID: <11174@brl-adm.ARPA> Date: 7 Jan 88 23:25:49 GMT Sender: news@brl-adm.ARPA Lines: 46 The attached program seems to work. Whether or not it ends up in a register seems to be compiler dependant but I had no complaints about the syntax and it always produced the expected results. On the Sun it ends up in a register when compiled with a -O flag but not if not. On an Encore/Multimax (Greenhill's C) and Vax (4.3bsd) it never ends up in a register. I couldn't really tell on the Celerity but I think it ends up in a register both optimized and unoptimized (I had trouble reading the machine code, not their fault, mostly I was too lazy to try to follow it carefully.) The optimizer for PCC on the 3090 (IBM370) is not available but it ended up in a register unoptimized. I'll leave it to the language lawyers as to whether or not it *should* have worked. -Barry Shein, Boston University #include /* * Bit patterns for 23.7 on various machines */ #define SUN 1 #if SUN | UMAX | CELERITY #define TWENTYTHREEPTSEVEN 0x41bd999a #endif #if IBM370 #define TWENTYTHREEPTSEVEN 0x4217b333 #endif #if VAX #define TWENTYTHREEPTSEVEN 0x999a42bd #endif main() { register union foo { int a; float b; } x; float z; x.a = TWENTYTHREEPTSEVEN; /* bit pattern for 23.7 float */ z = x.b; printf("%f\n",z); }