Hi Jason, On 24/05/2019 08.07, Jason Gunthorpe wrote: > On Thu, May 23, 2019 at 11:14:42PM -0700, Gerd Rausch wrote: > >> I can't say that I'm thrilled with this behavior though, >> as it appears error-prone: >> As soon as an enum value goes out of range for an "int", the >> type silently changes, potentially rendering structures and functions silently incompatible. >> It's quite the pitfall (e.g. the foo.c vs bar.c case above). > > Indeed, I would be very careful using this extension with > non-anonymous enums :) > > However, an anonymous enum can never have storage allocated, so it > doesn't experience any ABI concern. > Sure it can: % cat foo.c struct foo { enum { FOO = 1UL << 31 } foo; } foo = { FOO }; % gcc -Wall -g -c foo.c && gdb -batch -ex 'print sizeof foo' foo.o $1 = 4 % cat bar.c struct bar { enum { FOO = 1UL << 31, BAR = -1 } bar; } bar = { BAR }; % gcc -Wall -g -c bar.c && gdb -batch -ex 'print sizeof bar' bar.o $1 = 8 > It is a good and very useful extension, it is unfortuntate that C11 > did not standardize it. (C++11 did though) > Thanks for the info again. I guess I'm still stuck in 99 ;-) Cheers, Gerd