home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!cs.utexas.edu!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!udecc.engr.udayton.edu!blackbird.afit.af.mil!dsacg3.dsac.dla.mil!nto0302
- From: nto0302@dsacg3.dsac.dla.mil (Bob Fisher)
- Newsgroups: comp.lang.c
- Subject: Re: initiaklizing union members
- Message-ID: <5391@dsacg3.dsac.dla.mil>
- Date: 23 Jul 92 11:33:57 GMT
- References: <1708@toro.MTS.ML.COM>
- Distribution: usa
- Organization: Defense Logistics Agency Systems Automation Center, Columbus
- Lines: 28
-
- From article <1708@toro.MTS.ML.COM>, by scott@toro.MTS.ML.COM (Scott Strool):
- | How can I initialize a struct that contains a union member.
- | If I have a struct as defined:
- |
- | struct Row {
- | int Type;
- | union {
- | int ival;
- | char* sval;
- | } value;
- | };
- |
- | how would i set value with a static declaration:
- |
- | static Row r0 = { 0, 1234 };
- | static Row r1 = { 1, "string" };
- |
- | This does not work!
-
- I don't know if this is a compiler problem or a syntax problem. I
- suggest that you try initializing Row r1 with a pointer, not a string.
- If that doesn't help, try placing int Type after the union. The union
- may or may not be aligning on a word boundary.
- --
- Bob Fisher
- EMAIL: bfisher@dsac.dla.mil osu-cis!dsacg1!bfisher
- VOICE: Commercial 1-614-692-9071 Autovon 850-9071
- USPS: Defense Logistics Agency, DSAC-TOL, Box 1605, Columbus OH 43216-5002
-