Lvalue.bitfield type when the underlying bitfield type is not int in C

Someone drew my attention to the following program:

#include <stdio.h>

struct X50 {
 long long int z:50;
} s50 = { 2 };

struct X10 {
 long long int z:10;
} s10 = { 2 };

int main() {
  printf("%zu %zu %zu\n",sizeof(long long int),sizeof(s10.z+1),sizeof(s50.z+1));
}

The type of the expression is sizeof(lv.z+1)calculated in accordance with the "usual arithmetic transformations", which largely indicates that the type size for the lvalue lv.zwill be reflected in the type of addition, if not less int.

I did not expect this type to depend on the size of the bit field, but it does: both GCC and Clang print 8 4 8on my computer.

, C99, 2 6.3.1.1, , , , _Bool, int, signed int unsigned int. : " int , int,...", , , , long long int.

, 6.7.2.1 :

, _Bool, int, unsigned int - .

, long long int , - GCC C99?

StackOverflow, " ", , Clang GCC, S10.z int.

+5
1

6.7.2.1 10 ( ):

, - . , -, . , -, , - . - ( ). .

, ( , ), , , , , , . , 4 .

+3

All Articles