質問

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top