This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Does traditional C allow initializing a union?
- To: "Kaveh R. Ghazi" <ghazi at caip dot rutgers dot edu>
- Subject: Re: Does traditional C allow initializing a union?
- From: Andreas Schwab <schwab at issan dot informatik dot uni-dortmund dot de>
- Date: 13 Oct 1998 11:00:58 +0200
- Cc: egcs at cygnus dot com
- References: <199810130353.XAA13237@caip.rutgers.edu>
"Kaveh R. Ghazi" <ghazi@caip.rutgers.edu> writes:
|> (Okay this is a C question not an egcs one, but it relates to egcs code.)
|>
|> Does traditional C allow initializing a union? Eg:
|>
|> > typedef union rtunion_def
|> > {
|> > long rtwint;
|> > int rtint;
|> > char *rtstr;
|> > } rtunion;
|> >
|> > static rtunion foo = {0};
|>
|> This works under all ansi compilers I've found, but it fails for
|> me on SunOS4 cc and Irix4 'cc -cckr'. Is there another way to
|> initialize a union?
In this case just leaving out the initializer is exactly equivalent to the
above code, since variables with static storage duration that are not
initialized explicitly are guaranteed to be initialized to an appropriate
kind of zero. I think this is also true for K&R C, surely for SunOS.
--
Andreas Schwab "And now for something
schwab@issan.cs.uni-dortmund.de completely different"
schwab@gnu.org