Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!lavaca.uh.edu!nntppost From: jet@karazm.math.uh.edu ("J. Eric Townsend") Newsgroups: comp.lang.c Subject: Need help with union trick Message-ID: <1991Jan3.005700.20623@lavaca.uh.edu> Date: 3 Jan 91 00:57:00 GMT Sender: nntppost@lavaca.uh.edu (NNTP Posting Service) Organization: University of Houston -- Department of Mathematics Lines: 36 I don't think this is possible in C (K&R or ANSI), but maybe someone can enlighten me as to the hows and whys of why it is/isnt' possible. I have a body of code with the following structure: typedef struct pointstruct { double x,y,z; } Point; I would like to be able to reference the elements as an array without having to rewrite the existing code. (We've got code to be pasted in that relies on being able to grab the x, y and z as array indicies. Grr. :-) ie: foo.x = 1.0; /* or */ foo[0] = 1.0; Here's the bind, as I see it.: Point babble[100]; a = babble[0].x; /* vs */ a = babble[0][0]; This: typedef union pointstruct { double x,y,z; double foo[3]; } Point; would union x, y and z to foo[0], which is not what I want... Again, I'm not sure if there's any way to do this. (The current solution is to have the "magic copy" routine, which is ugly and slow, but gets the job done.) -- J. Eric Townsend Internet: jet@uh.edu Bitnet: jet@UHOU Systems Mangler - UH Dept. of Mathematics - (713) 749-2120 Skate UNIX, boyo.