Is there a way to declare space in a struct as unused / filler / pad, in such as way as to not have to provide an identifier?
For example,
Code:struct foo { int . ; // just 4 bytes, padding for later, don't need it now int myval ; } ;
Is there a way to declare space in a struct as unused / filler / pad, in such as way as to not have to provide an identifier?
For example,
Code:struct foo { int . ; // just 4 bytes, padding for later, don't need it now int myval ; } ;
Mainframe assembler programmer by trade. C coder when I can.
You can have unnamed bit-fields.
Though 99% of people will just say this and think no more of it.Code:#include<stdio.h> #include<stdlib.h> #include<stddef.h> int main() { struct foo { int : 32; int myval; } bar; bar.myval = 42; printf("%zd\n",offsetof(struct foo,myval)); return 0; }
Code:struct foo { int dummy; int myval; };
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.