Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!yale!cmcl2!kramden.acf.nyu.edu!brnstnd From: brnstnd@kramden.acf.nyu.edu (Dan Bernstein) Newsgroups: comp.lang.c Subject: Re: Need help with union trick: summary of replies Message-ID: <4977:Jan422:17:0191@kramden.acf.nyu.edu> Date: 4 Jan 91 22:17:01 GMT References: <1991Jan4.192645.7094@lavaca.uh.edu> Organization: IR Lines: 35 In article <1991Jan4.192645.7094@lavaca.uh.edu> jet@karazm.math.uh.edu ("J. Eric Townsend") writes: > I received many replies, some using #defines, others requiring other > changes. I think the following message best summaraizes the answers that > work the best. The #define answers are the only safe ones so far. I wouldn't recommend any of the others for anything you're planning to use on several machines. [ ANSI anonymous structures: ] > | typedef union pointstruct { > | struct { > | double x, y, z; > | }; > | double foo [3]; > | } Point; This is not guaranteed to work because the structure elements might not be contiguous, or even in order. The right solution for a language designer is context definitions: typedef struct pointstruct { double foo[3]; define x foo[0]; define y foo[1]; define z foo[2]; } Point; This would solve the same problems as ANSI anonymous structures but would be a lot safer for unions. ---Dan