Initializing bit fields
Erik Talvola
talvola at janus.Berkeley.EDU
Wed Jun 27 09:34:10 AEST 1990
In article <1656 at crabcake> zhu at cs.jhu.edu (Benjamin Zhu) writes:
In article <7330025 at hpcllca.HP.COM> walter at 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 at janus.berkeley.edu | space wedgie of great power coming right at us
! ...!ucbvax!janus!talvola | at warp speed." -- Star Drek
More information about the Comp.lang.c
mailing list