home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / c / 11514 < prev    next >
Encoding:
Internet Message Format  |  1992-07-23  |  1.3 KB

  1. 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
  2. From: nto0302@dsacg3.dsac.dla.mil (Bob Fisher)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: initiaklizing union members
  5. Message-ID: <5391@dsacg3.dsac.dla.mil>
  6. Date: 23 Jul 92 11:33:57 GMT
  7. References: <1708@toro.MTS.ML.COM>
  8. Distribution: usa
  9. Organization: Defense Logistics Agency Systems Automation Center, Columbus
  10. Lines: 28
  11.  
  12. From article <1708@toro.MTS.ML.COM>, by scott@toro.MTS.ML.COM (Scott Strool):
  13. | How can I initialize a struct that contains a union member.
  14. | If I have a struct as defined:
  15. | struct Row {
  16. |     int Type;
  17. |     union {
  18. |         int ival;
  19. |         char* sval;
  20. |         } value;
  21. |     };
  22. | how would i set value with a static declaration:
  23. | static Row r0 = { 0, 1234 };
  24. | static Row r1 = { 1, "string" };
  25. | This does not work!
  26.  
  27. I don't know if this is a compiler problem or a syntax problem.  I
  28. suggest that you try initializing Row r1 with a pointer, not a string.
  29. If that doesn't help, try placing int Type after the union.  The union
  30. may or may not be aligning on a word boundary.
  31. -- 
  32. Bob Fisher
  33. EMAIL:    bfisher@dsac.dla.mil          osu-cis!dsacg1!bfisher
  34. VOICE:    Commercial 1-614-692-9071    Autovon 850-9071
  35. USPS:     Defense Logistics Agency, DSAC-TOL, Box 1605, Columbus OH 43216-5002
  36.