delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/09/23/23:17:47

From: Eric Amick <eamick AT clark DOT net>
Subject: Re: How do I initialize a union?
Newsgroups: comp.os.msdos.djgpp,comp.lang.c
References: <7secmg$8nd$1 AT solomon DOT cs DOT rose-hulman DOT edu>
Organization: the end of my rope
User-Agent: tin/pre-1.4-980105 (UNIX) (SunOS/5.6 (sun4u))
Lines: 25
Message-ID: <hkBG3.8372$zI3.123194@iad-read.news.verio.net>
Date: Fri, 24 Sep 1999 02:27:25 GMT
NNTP-Posting-Host: 168.143.0.8
X-Complaints-To: abuse AT verio DOT net
X-Trace: iad-read.news.verio.net 938140045 168.143.0.8 (Fri, 24 Sep 1999 02:27:25 GMT)
NNTP-Posting-Date: Fri, 24 Sep 1999 02:27:25 GMT
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

In comp.lang.c Damian Yerrick <web DOT poison AT pineight DOT 8m DOT com> wrote:

> typedef union Foo
> {
>   void *data;
>   Boxers trunks;
> } Foo;

> Foo bar;

> How do I set up a declaration that defines an initial value for
> bar.data or bar.trunks?

If you mean an actual initializer, it has to be for the first element
declared in the union:

Foo bar = {NULL};

If you want to set data sometimes and trunks other times, you'll have to
use an assignment.

-- 
Eric Amick
Columbia, MD
eamick AT clark DOT net

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019