tech-kern archive

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

Re: setsockopt() compat issue



Joerg Sonnenberger wrote:
On Sun, Oct 19, 2008 at 01:07:22PM +0200, Johnny Billquist wrote:
How about the fact that the C standard says that an int should be the "native word size of the hardware"?

Where? I can find only a single place where "native" is used in the C99
specification and it should be noted that e.g. sizeof() is specified to
return size_t, not int. That makes it pretty clear that none of the
standard types is guarantied to always have the same size as a pointer
or even an index.

Reading ISO/IEC 9899:TC2 right now. I'm not exactly sure how much of C99 this is, or if it's related to the new standards that's being worked on.

Anyway, in section 6.2.5, Types, it says this in paragraph 5:

===
An object declared as type signed char occupies the same amount of storage as a "plain" char object. A "plain" int object has the natural size suggested by the architecture of the execution environment (large enough to contain any value in the range INT_MIN to INT_MAX as defined in the header <limits.h>).
===

Note the "natural size suggested by the architecture of the execution environment".

The very concept of "native word size" is fuzzy, as soon as hardware has
registers of different sizes. For most purposes size_t is reasonable,
but not always. It can be more efficient to use shorter registers, e.g.
on AMD64 you get shorter opcodes.

Interesting. Which archtecture have registers of different sizes? I can't really think of any, except a few cases where subparts of a register can be referred to individually, but that don't change the actual word size of the register.
But I definitely don't know all the architecture that exist.

However, even so, that don't change the way the standard defines an int. Fuzzy or not. Unless I remember wrong, they intentionally left it fuzzy for the simple fact that they wanted to leave this open to the compiler writes to do as they found most suitable.

        Johnny



Home | Main Index | Thread Index | Old Index