home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!charon.amdahl.com!pacbell.com!mips!mips!munnari.oz.au!cs.mu.OZ.AU!munta.cs.mu.OZ.AU!fjh
- From: fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON)
- Subject: Re: initiaklizing union members
- Message-ID: <9220904.24599@mulga.cs.mu.OZ.AU>
- Sender: news@cs.mu.OZ.AU
- Organization: Computer Science, University of Melbourne, Australia
- References: <1708@toro.MTS.ML.COM> <5391@dsacg3.dsac.dla.mil> <24901@dog.ee.lbl.gov>
- Distribution: usa
- Date: Sun, 26 Jul 1992 18:09:46 GMT
- Lines: 31
-
- torek@horse.ee.lbl.gov (Chris Torek) writes:
-
- >If you have an ANSI C compiler, you can get away with this:
- >
- > struct Row {
- > int Type;
- > union {
- > int ival;
- > char *sval;
- > } value;
- > };
- > struct Row_str {
- > int Type;
- > union {
- > char *sval;
- > int ival;
- > } value;
- > };
- > static Row r0 = { 0, 1234 };
- > static Row_str r1_str = { 1, "string" };
- > #define r1 (*(struct Row *)&r1_str)
-
- Isn't it the case that *technically*, to be sure that the definitions
- for Row and Row_str are are compatible, you have to define them in
- seperate compilation units?
-
- --
- Fergus Henderson fjh@munta.cs.mu.OZ.AU
- This .signature VIRUS is a self-referential statement that is true - but
- you will only be able to consistently believe it if you copy it to your own
- .signature file!
-