From owner-freebsd-hackers Tue Aug 4 18:51:12 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id SAA11151 for freebsd-hackers-outgoing; Tue, 4 Aug 1998 18:51:12 -0700 (PDT) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from dingo.cdrom.com (dingo.cdrom.com [204.216.28.145]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id SAA11146 for ; Tue, 4 Aug 1998 18:51:11 -0700 (PDT) (envelope-from mike@dingo.cdrom.com) Received: from dingo.cdrom.com (localhost [127.0.0.1]) by dingo.cdrom.com (8.8.8/8.8.5) with ESMTP id SAA01073; Tue, 4 Aug 1998 18:49:28 -0700 (PDT) Message-Id: <199808050149.SAA01073@dingo.cdrom.com> X-Mailer: exmh version 2.0zeta 7/24/97 To: Terry Lambert cc: chuckr@glue.umd.edu (Chuck Robey), Nicolas.Souchu@prism.uvsq.fr, freebsd-hackers@FreeBSD.ORG Subject: Re: C and static initialization with unions In-reply-to: Your message of "Wed, 05 Aug 1998 01:03:14 -0000." <199808050103.SAA27705@usr02.primenet.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Tue, 04 Aug 1998 18:49:27 -0700 From: Mike Smith Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG > > > union foo_t { > > > int i; > > > char c; > > > void *p; > > > }; > > > > > > static union foo_t bar = { (void *)&anyvar }; > > > > No, you forgot to mention which union memeber to use. Your foo_t.p > > would do nicely. > > 1) This is a vendor extension. > > 2) That vendor isn't FSF or Cygnus. > > 3) It's "foo_t bar.p", not "foo_t.p bar". > > 4) It still breaks for: > > typedef enum { UT_INT, UT_CHAR, UT_PTR } ut_t; > > typedef struct { > ut_t u_type; > struct foo_t u; /* someone blew a typedef*/ > } bob_t; > > bob_t bobs.p[] = { > { UT_PTR, &anyvar }, > { UT_INT, 35 }, /* oops!*/ > { UT_PTR, NULL } > }; > The gcc info "extensions/named elements" section describes a useful extension that lets you cut through much of this crap. -- \\ Sometimes you're ahead, \\ Mike Smith \\ sometimes you're behind. \\ mike@smith.net.au \\ The race is long, and in the \\ msmith@freebsd.org \\ end it's only with yourself. \\ msmith@cdrom.com To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message