Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when initializing multiple bit fields #1283

Open
fafner2000 opened this issue May 3, 2024 · 1 comment
Open

Error when initializing multiple bit fields #1283

fafner2000 opened this issue May 3, 2024 · 1 comment
Labels
bug C C compiler

Comments

@fafner2000
Copy link

Hello,

I found an issue when initializing multiple bit fields:

typedef struct
  {
  int field1,field2;
  unsigned int bit1:1,bit2:1;
  } some_struct;

static const some_struct S=
  {
  .field1=1,
  .field2=2,
  .bit1  =0,
  .bit2  =1,  // <- E1063: Missing operand
  };

It gives this error:
test.c(27): Error! E1063: Missing operand

This error doesn't depend on the presence of the trailing comma. Using -za99 doesn't change anything either. However, the error goes away when removing one of the bit field initializers (either bit1 or bit2). The error also goes away when using array-style initialization:

static const some_struct S={1,2,0,1};

I had a watch in the ISO/IEC 9899:1999 reference, section 6.7.8 , to make sure there wasn't some restriction on bit fields initialization, but didn't see anything special about them. Moreover, everything compiles fine with gcc.

@jmalak
Copy link
Member

jmalak commented May 3, 2024

#1262 #1274

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug C C compiler
Projects
None yet
Development

No branches or pull requests

2 participants