Re: 0xdeadbeef vs 0xdeadbeefL

From: H. Peter Anvin
Date: Mon Jul 12 2004 - 12:33:02 EST


Followup to: <orn02cqs3u.fsf@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
By author: Alexandre Oliva <aoliva@xxxxxxxxxx>
In newsgroup: linux.dev.kernel
>
> On Jul 6, 2004, Ray Lee <ray-lk@xxxxxxxxxxxxx> wrote:
>
> > Which means 0xdeadbeef is a perfectly valid literal for an unsigned int.
>
> Assuming ints are 32-bits wide. They don't have to be. They could be
> as narrow as 16 bits, in which case the constant will have type long
> or unsigned long (because long must be at least 32 bits), or they
> could be wider than 32 bits, in which case the constant will be signed
> int instead of unsigned int. You might lose either way. It's
> probably safer to make it explicitly UL, except perhaps in
> machine-specific files where the width of types is well-known.
>

If it runs Linux:

CHAR_BIT == 8
sizeof(int) == 4
sizeof(void(*)()) == sizeof(void *)
sizeof(long) == sizeof(void *)
sizeof(long long) == 8
(long)NULL == 0L

These assumptions are pretty ingrained in the Linux kernel.

-hpa
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/