This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Does traditional C allow initializing a union?


"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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]