I compiled this (gcc compiler):
#include <stdio.h>
main() {
struct {
a:1;
b:2;
} t;
t.b=6;
t.a=2;
printf("%d %d",t.a,t.b);
}
Error shown was:
expected specifier-qualifier list before 'a'
Why it is needed when unnamed data variables are taken as int by default. Please explain...
This is required by the C language standard. According to section 6.7.2.1 part 4:
A bit-field shall have a type that is a qualified or unqualified version of _Bool, signed int, unsigned int, or some other implementation-defined type.