Re: [OT] sizeof C types ...

From: Erik Andersen
Date: Mon Aug 25 2003 - 17:38:20 EST


On Mon Aug 25, 2003 at 09:38:37PM +0200, Herbert Pötzl wrote:
> thanks, almost figured that, but I'm looking for
> a tabular info where the different architectures
> are present like the folowing:
>
> i386 | ia64 | alpha | sparc | wossname ...
> -----------+-------+------+-------+-------+-------------------
> char | 8 | | | |
> short | 16 | | | |
> int | 32 | | | |
> long | 32 | | | |
> long long | 64 | | | |

If one cares about the exact number of bits, IMHO one should be
using stdint.h, as defined by ISO-IEC-9899-1999 (C99), section
7.18 Integer types.

Using type such as int8_t, int16_t, int32_t, int64_t, and
uint8_t, uint16_t, uint32_t, uint64_t are the One True Way of
reliably, portably, getting the number of bits you want. It
would be very nice if the kernel were converted to use these
types as well. It would also be nice if every architecture
properly supported C99. Unfortunately, that is not true on
either count. For example, if you want your code to interoperate
with windoz, you will want to do something such as....

#if defined(_WIN32) || defined(__WIN32__)
# define uint8_t unsigned __int8
# define uint16_t unsigned __int16
# define uint32_t unsigned __int32
# define uint64_t unsigned __int64
# define int8_t __int8
# define int16_t __int16
# define int32_t __int32
# define int64_t __int64
#else
# include <stdint.h>
#endif

-Erik

--
Erik B. Andersen http://codepoet-consulting.com/
--This message was written using 73% post-consumer electrons--
-
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/