[Bug c/65471] type interpretation in _Generic
wink at saville dot com
gcc-bugzilla@gcc.gnu.org
Tue Feb 23 03:18:00 GMT 2016
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65471
Wink Saville <wink at saville dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |wink at saville dot com
--- Comment #3 from Wink Saville <wink at saville dot com> ---
Tested on on gcc 5.3.0 on an x86_64 Arch Linux machine.
When using bit field as a selector _Generic uses the default path
and in the following test program outputs "unknown":
$ cat test.c
$ cat test.c
#include <stdio.h>
struct S {
int b0:4;
unsigned int b1:4;
unsigned long long int b33:33;
};
#define type2str(__x) _Generic((__x), \
int : "int", \
unsigned int : "unsigned int", \
unsigned long long int : "unsigned long long int", \
default : "unknown")
int main(void) {
struct S s = { .b0=3, .b1=4, .b33=0x1FFFFFFFF };
(void)s; // Not used
// gcc | clang output
printf("type2str(s.b0): %s\n", type2str(s.b0)); // unknown | int
printf("type2str(s.b1): %s\n", type2str(s.b1)); // unknown | unsigned int
printf("type2str(s.b33): %s\n", type2str(s.b33));// unknown | unsigned long
long int
return 0;
}
$ cat Makefile
CC = gcc
O = 3
STD = c11
M = 32
test: test.c Makefile
$(CC) -O$(O) -m$(M) -Wall -std=$(STD) test.c -o test
clean:
rm -f test
$ make clean ; make CC=gcc ; ./test
rm -f test
gcc -O3 -m32 -Wall -std=c11 test.c -o test
type2str(s.b0): unknown
type2str(s.b1): unknown
type2str(s.b33): unknown
$ make clean ;make CC=clang ; ./test
rm -f test
clang -O3 -m32 -Wall -std=c11 test.c -o test
type2str(s.b0): int
type2str(s.b1): unsigned int
type2str(s.b33): unsigned long long int
Additional discussion on gcc thread:
https://gcc.gnu.org/ml/gcc/2016-02/msg00255.html
More information about the Gcc-bugs
mailing list