Newsgroups: comp.lang.c Path: utzoo!henry From: henry@zoo.toronto.edu (Henry Spencer) Subject: Re: What breaks? (was Re: 64 bit longs?) Message-ID: <1991Jan18.173033.788@zoo.toronto.edu> Organization: U of Toronto Zoology References: <54379@eerie.acsu.Buffalo.EDU> <1991Jan15.053356.2631@zoo.toronto.edu> <1991Jan15.202123.14223@gjetor.geac.COM> <14890@smoke.brl.mil> <1991Jan18.044948.27943@zoo.toronto.edu> <1991Jan18.094133.16879@watmath.waterloo.edu> Date: Fri, 18 Jan 1991 17:30:33 GMT In article <1991Jan18.094133.16879@watmath.waterloo.edu> datangua@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@zoo.toronto.edu utzoo!henry