gcc_bit_field_types.c revision 1.5
1/* $NetBSD: gcc_bit_field_types.c,v 1.5 2021/05/04 05:40:10 rillig Exp $ */ 2# 3 "gcc_bit_field_types.c" 3 4/* 5 * https://gcc.gnu.org/onlinedocs/gcc/Structures-unions-enumerations-and-bit-fields-implementation.html 6 * 7 * "Other integer types, such as long int, and enumerated types are permitted 8 * even in strictly conforming mode." 9 * 10 * See msg_035.c. 11 */ 12 13struct example { 14 int int_flag: 1; 15 unsigned int unsigned_int_flag: 1; 16 long long_flag: 1; 17 unsigned long unsigned_long_flag: 1; 18 long long long_long_flag: 1; 19 unsigned long long unsigned_long_long_flag: 1; 20 double double_flag: 1; /* expect: illegal bit-field type 'double' */ 21}; 22 23struct large_bit_field { 24 unsigned long long member: 48; 25}; 26 27unsigned long long 28promote_large_bit_field(struct large_bit_field lbf) 29{ 30 /* 31 * Before tree.c 1.281 from 2021-05-04: 32 * lint: assertion "len == size_in_bits(INT)" failed 33 * in promote at tree.c:1698 34 */ 35 return lbf.member & 0xf; 36} 37