Pelles C forum

Pelles C => Bug reports => Topic started by: iZzz32 on October 12, 2011, 10:37:56 PM

Title: [FIXED] Bitfields initialization
Post by: iZzz32 on October 12, 2011, 10:37:56 PM
Code: [Select]
typedef struct Foo
{
  bool              foo:1;
  bool              bar:1;
  bool              baz:1;
  unsigned          qux;
 
} Foo;

Foo f = { true, .bar = 1, 1, 12345 };

The code above does not initialize .bar and .baz to 1, however GCC behaves as expected (http://ideone.com/9T13z). Is this a bug?  ;)

(Pelles C 6.50 RC 4, pocc.exe is 6.50.35.0), 7.00 RC 1 too
Title: Re: [BUG?] Bitfields initialization
Post by: CommonTater on October 13, 2011, 03:12:59 AM
http://tigcc.ticalc.org/doc/gnuexts.html#SEC82

I think you will find that the .bar=1 syntax is not standard C, but is infact a GCC specific extension to the C language.


Title: Re: [BUG?] Bitfields initialization
Post by: Bitbeisser on October 13, 2011, 08:20:03 AM
http://tigcc.ticalc.org/doc/gnuexts.html#SEC82

I think you will find that the .bar=1 syntax is not standard C, but is infact a GCC specific extension to the C language.
I am not so sure, as the reference you posted says it's standard in C99 but GCC allows it as an extensio to C89.

Pelles C however claims to be C99 compliant...   ???

Ralf
Title: Re: [BUG?] Bitfields initialization
Post by: iZzz32 on October 13, 2011, 12:20:13 PM
Quote
I think you will find that the .bar=1 syntax is not standard C
This syntax is standard C99 (ISO/IEC 9899:1999, 6.7.8, paragraph 7) and Pelles C supports it (according to the reference in the help file).

But it does not matter, because Foo f = { 1, 1, 1, 12345 }; does not work either.
Title: Re: [BUG?] Bitfields initialization
Post by: iZzz32 on May 28, 2012, 04:10:37 PM
Still present in RC3. Is it an error to initialize bit-fields like this? Then why does it work when I change bool to unsigned?
Code: [Select]
#include <stdbool.h>
#include <assert.h>
 
typedef struct Foo
{
  bool              a:1;
  bool              b:1;
} Foo;
 
Foo f = { true, true };
 
int main(void)
{
  assert(f.a && f.b);
  return 0;
}
Title: Re: [BUG?] Bitfields initialization
Post by: Pelle on June 03, 2012, 05:15:50 PM
It looks like a bug, but I have to check. I think the problem is that _Bool is full byte, but you are not allowed to use more than one bit (so you can't pack several bits into a _Bool). At some point I think there was some cunfusion if, for example, "_Bool x:3" was allowed, and if so, what it meant...