What breaks? (was Re: 64 bit longs?)

Henry Spencer henry at zoo.toronto.edu
Sat Jan 19 04:30:33 AEST 1991


In article <1991Jan18.094133.16879 at watmath.waterloo.edu> datangua at watmath.waterloo.edu (David Tanguay) writes:
>>There is no portable way to declare a type with *exactly* 32 bits, and
>>a TCP/IP sequence number (for example) is exactly 32, no more.
>
>How about: (Standard C only)
>
>typedef struct { long it:32; } net32_t;
>#define net32_t(var) var.it

Unfortunately, there is no guarantee that padding won't get added to the
end of that struct to bring it up to a size that the hardware likes.
The number will be only 32 bits -- modulo all the fuzziness of bitfields,
which are quite implementation-dependent -- but you won't be able to
declare headers using this.

>I don't like sticking the 32 in the type name, since that may change,

It would be better to use something like seq_t for a TCP/IP sequence
number, for graceful handling of later extensions.  However, the whole
point of this example is that the TCP/IP specification guarantees that
the field in the header structure is exactly, precisely 32 bits, and that
is not going to change.  (Extensions are by options that add data later,
not by changes to the basic structure.)  You would use net32_t in cases
where you really did want exactly 32 bits and no backtalk.
-- 
If the Space Shuttle was the answer,   | Henry Spencer at U of Toronto Zoology
what was the question?                 |  henry at zoo.toronto.edu   utzoo!henry



More information about the Comp.lang.c mailing list