... the actual type makes a difference in C11 with _Generic
The results of how 1 compiler treats the bit field types is shown below.
The 8-bit and 32-bit fields match the usual suspects.
What is the type of a 1-bit bitfield? As others have cited, its "name" is not clearly specified, but it is not any of the expected standard types.
This does not cite a specification, but does demonstrate how a respected compiler interpreted the C spec.
GNU C11 (GCC) version 5.3.0 (i686-pc-cygwin)
compiled by GNU C version 5.3.0, GMP version 6.1.0, MPFR version 3.1.4, MPC version 1.0.3
#define info_typename(X) _Generic((X), \
_Bool: "_Bool", \
unsigned char: "unsigned char", \
signed char: "signed char", \
char: "char", \
int: "int", \
unsigned : "unsigned", \
default: "default" \
)
#define TYPE_NAME(t) { printf("%s\n", info_typename(t)); }
#include <stdio.h>
int main() {
struct {
signed int x1 :1;
signed int x8 :8;
signed int x32 :32;
_Bool b;
signed char sc;
char c;
unsigned char uc;
int i;
unsigned u;
} foo;
TYPE_NAME(foo.b);
TYPE_NAME(foo.sc);
TYPE_NAME(foo.c);
TYPE_NAME(foo.uc);
TYPE_NAME(foo.i);
TYPE_NAME(foo.u);
TYPE_NAME(foo.x1);
TYPE_NAME(foo.x8);
TYPE_NAME(foo.x32);
}
Output
_Bool
signed char
char
unsigned char
int
unsigned
default (int:1)
signed char (int:8)
int (int:32)
Note with -Wconversion
and the below code, I get this warning. So that is at least what one compiler calls its small bit field type: unsigned char:3
.
warning: conversion to 'unsigned char:3' from 'unsigned int' may alter its value [-Wconversion]
struct {
unsigned int x3 :3;
} foo;
unsigned u = 1;
foo.x3 = u; // warning