2004-11-03 13:31:19

by Roman Fietze

[permalink] [raw]
Subject: PATCH: stdint constants

Hello,

First of all: sorry for using Notes MUA, but cannot route to kernel.org
due to NJABL.

Allthough many books recommend using the types uint8_t to uint64_t as
well as their signed counterparts, I could not find the MIX/MAX values
for those types in any kernel include file.

Tested on a 2.4 ARM/PPC/I386 kernel with gcc 3.0.4/3.2.2/3.3.2. Not
tested on any 64 bit architecture.

Any comments to this patch?


diff -uprN linux-2.6.9/include/linux/kernel.h
linux-2.6.9-stdint/include/linux/kernel.h
--- linux-2.6.9/include/linux/kernel.h 2004-10-18 23:53:05.000000000
+0200
+++ linux-2.6.9-stdint/include/linux/kernel.h 2004-11-03
14:15:24.000000000 +0100
@@ -23,6 +23,30 @@
#define LONG_MIN (-LONG_MAX - 1)
#define ULONG_MAX (~0UL)

+#define INT8_MIN (-128)
+#define INT16_MIN (-32767-1)
+#define INT32_MIN (-2147483647-1)
+
+#define INT8_MAX (127)
+#define INT16_MAX (32767)
+#define INT32_MAX (2147483647)
+
+#define UINT8_MAX (255)
+#define UINT16_MAX (65535)
+#define UINT32_MAX (4294967295U)
+
+#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
+# if BITS_PER_LONG == 32
+# define INT64_MIN (-9223372036854775807LL - 1LL)
+# define INT64_MAX (9223372036854775807LL)
+# define UINT64_MAX (18446744073709551615ULL)
+# else
+# define INT64_MIN (-9223372036854775807L - 1L)
+# define INT64_MAX (9223372036854775807L)
+# define UINT64_MAX (18446744073709551615UL)
+# endif
+#endif
+
#define STACK_MAGIC 0xdeadbeef

#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))



Roman

--
Roman Fietze Telemotive AG B?ro M?hlhausen
Breitwiesen 73347 M?hlhausen
Tel.: +49(0)7335 18493-45 http://www.telemotive.de


2004-11-04 17:54:38

by H. Peter Anvin

[permalink] [raw]
Subject: Re: PATCH: stdint constants

Followup to: <[email protected]>
By author: [email protected]
In newsgroup: linux.dev.kernel
>
> Hello,
>
> First of all: sorry for using Notes MUA, but cannot route to kernel.org
> due to NJABL.
>
> Allthough many books recommend using the types uint8_t to uint64_t as
> well as their signed counterparts, I could not find the MIX/MAX values
> for those types in any kernel include file.
>
> Tested on a 2.4 ARM/PPC/I386 kernel with gcc 3.0.4/3.2.2/3.3.2. Not
> tested on any 64 bit architecture.
>
> Any comments to this patch?
>

Yes. Long long is a ISO C99 type guaranteed to be at least 64 bits.
Thus,

#if defined(__GNUC__) && !defined(__STRICT_ANSI__)

is wrong; it's in fact actively harmful.

Furthermore, this should only be used by the kernel, since this comes
from <stdint.h> in userspace.

<stdint.h> really should be a compiler-provided header file. Sigh.

-hpa