Re: cast truncates bits from constant value (8000000000000000 becomes 0)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On Fri, 1 Dec 2006, Linus Torvalds wrote:
> 
> But at times, some of the gcc extensions aren't necessarily that well 
> defined or thought out, or simply not worth it. The extended type system 
> for enums in gcc is just basically messy, and it doesn't really offer you 
> anything important.

Btw, try this stupid program, to see just how _strange_ gcc enums are.. A 
sizeof of the enum is not the same as the size of the individual entries. 

Notice also how the size of the enum entry is _not_ tied to the type of 
the expression it had, but literally to its _value_. The size of "one" 
ends up being 4, even though it was initialized with a "1ll" value.

So with gcc-enums, you CANNOT get a sane type result.

In contrast, if you want sane types, you could easily do

	#define one (1ull)
	#define other (0x10000ull)
	#define strange (0x100000000ull)

and they'd all have the same type (and having the same type means that 
they act the same in expressions - you get the same expression type in 
mixing these values, _unlike_ the insane gcc enum cases)

		Linus

---
enum hello {
	one = 1ll,
	other = 0x10000,
	bigval = 0x1000000000000ll,
};

int main(int argc, char **argv)
{
	printf("%zu %zu %zu %zu\n",
		sizeof(enum hello),
		sizeof(one),
		sizeof(other),
		sizeof(bigval));
	return 0;
}
-
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux