Path: utzoo!attcan!uunet!cs.utexas.edu!uwm.edu!bionet!agate!agate!talvola From: talvola@janus.Berkeley.EDU (Erik Talvola) Newsgroups: comp.lang.c Subject: Re: Initializing bit fields Message-ID: Date: 26 Jun 90 23:34:10 GMT References: <1130@manta.NOSC.MIL> <7330025@hpcllca.HP.COM> <1656@crabcake> Sender: usenet@agate.berkeley.edu (USENET Administrator;;;;ZU44) Followup-To: comp.lang.c Organization: /staff/talvola/.organization Lines: 43 In-reply-to: zhu@cs.jhu.edu's message of 26 Jun 90 21:04:11 GMT In article <1656@crabcake> zhu@cs.jhu.edu (Benjamin Zhu) writes: In article <7330025@hpcllca.HP.COM> walter@hpcllca.HP.COM (Walter Murray) writes: >Scot Mcintosh asks: > >> Given: >> struct { >> int field1:1; >> :1; >> int field2:1; >> int field3:1; >> } var = {0,0,0}; > >> Does ANSI define which field the middle zero initializes, or is this >> implementation dependent? > >"All unnamed structure or union members are ignored during initialization." >ANSI 3.5.7 (page 72, line 38) Thus the middle zero initializes >field2. > That is what I thought before. However, after I tried this out with my gcc compiler, it turns out that at least gcc is not doing what I expected. Here is an example. ... example deleted ... Guess what's the printout? 1 1 0 /* should be 1 1 1 according to ANSI */ I just tried this on GCC 1.37.1 on a Sun 3/50, and it prints out 1 1 1 as according to ANSI-C - maybe you are using an older buggier version of GCC? -- +----------------------------+ ! Erik Talvola | "It's just what we need... a colossal negative ! talvola@janus.berkeley.edu | space wedgie of great power coming right at us ! ...!ucbvax!janus!talvola | at warp speed." -- Star Drek