Re: Use of C99 int types

From: Kyle Moffett
Date: Tue Apr 05 2005 - 16:59:12 EST


On Apr 05, 2005, at 08:18, Richard B. Johnson wrote:
One cannot just use 'int' or 'long', in particular when interfacing
with an operating system. For example, look at the socket interface
code. Parameters are put into an array of longs and a pointer to
this array is passed to the socket interface. It's a mess when
converting this code to 64-bit world.

Exactly

If originally one used a structure of the correct POSIX integer
types, and a pointer to the structure was passed, then absolutely
nothing in the source-code would have to be changed at all when
compiling that interface for a 64-bit machine.

But you _can't_ use the POSIX integer types. When compiling the
kernel, if you use the types, you must define them in the kernel
headers. On the other hand, when compiling userspace stuff, you
_can't_ have them defined in the kernel headers because libc also
defines them. The solution is to use __{s,u}{8,16,32,64}, which
are _only_ defined by the kernel, not by libc or gcc, and can be
therefore used in the ABI.

The continual short-cuts, with the continual "special-case"
hacks is what makes porting difficult. That's what the POSIX
types was supposed to help prevent.

Except the POSIX types themselves are not usable for the boundary
code for the reasons of double definition. Google for Linus'
posts on this topic a couple months ago.

That's why I think if there was a stdint.h file in the kernel,
when people were performing maintenance or porting their code,
they could start using those types.

The types _are_ available from the kernel headers, but only when
compiling with __KERNEL__, to avoid conflicts from the libc
definitions.

Cheers,
Kyle Moffett

-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GCM/CS/IT/U d- s++: a18 C++++>$ UB/L/X/*++++(+)>$ P+++(++++)>$
L++++(+++) E W++(+) N+++(++) o? K? w--- O? M++ V? PS+() PE+(-) Y+
PGP+++ t+(+++) 5 X R? tv-(--) b++++(++) DI+ D+ G e->++++$ h!*()>++$ r !y?(-)
------END GEEK CODE BLOCK------


-
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/