Path: utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!wuarchive!usc!jarthur!nntp-server.caltech.edu!juliet.caltech.edu!gceych From: gceych@juliet.caltech.edu (Eychaner, Glenn C.) Newsgroups: comp.lang.c Subject: Re: Need help with union trick: summary of replies Message-ID: <1991Jan12.190021.16071@nntp-server.caltech.edu> Date: 12 Jan 91 18:51:15 GMT References: <1991Jan4.192645.7094@lavaca.uh.edu> <4977:Jan422:17:0191@kramden.acf.nyu.edu> <28949@mimsy.umd.edu> <2885@cirrusl.UUCP> Sender: news@nntp-server.caltech.edu Reply-To: gceych@juliet.caltech.edu Organization: California Institute of Technology Lines: 34 News-Software: VAX/VMS VNEWS 1.3-4x Nntp-Posting-Host: juliet.caltech.edu dhesi%cirrusl@oliveb.ATC.olivetti.com (Rahul Dhesi) writes... >I sort of like calling the union substructure by tiny names like x, y, >z etc. Then references become struct_name.x.field_name, and the ".x." >is almost not noticeable. The idea is to use a small meaningless name >(sort of using i, j, k as loop counters) so the meaningfullness (to >coin a noun) lies entirely in the name of the structure and the name of >the field. >-- Me (in VaxC, I don't know if others support it) use variant_structures and variant_unions. Example: struct { variant_union { unsigned char ch; variant_struct { unsigned one : 1; unsigned two : 1; ... unsigned eig : 1; } superfluous; } superfluous2; int i, j, k, x, y, z; } mystructure; So you can reference the first bit of ch as mystructure.one, the second as mystructure.two, ch as mystructure.ch, i as mystructure.i, etc. All the variables must have different names, BTW. I use this for storing bit flags to a file as a char or int (to avoid huge scanf statements and files full of 1's & 0's). Glenn C. Eychaner | "We demand rigidly defined areas of doubt and uncertainty." 40386 N. Shore Ln `-----. -D. Adams Big Bear City, CA 92314 `-----------------------. !**** G O N I N E R S ****! Eychaner%SunCub.Caltech.edu@Xhmeia.Caltech.edu -|- Big Bear Solar Observatory