Struct usage and varying sizes of h, l, etc
Grant Edwards
grante at visi.com
Wed May 21 10:04:02 EDT 2008
On 2008-05-20, Robert Kern <robert.kern at gmail.com> wrote:
>> I'm looking at the struct module for binary packing of ints
>> and floats. The documentation refers to C datatypes. It's
>> been many years since I looked at C, but I seem to remember
>> that the data type sizes were not fixed -- for example, an int
>> might be two byes on one machine, and four bytes on the next.
>> Can any C programmers verify this? If it is true, does that
>> mean that struct.pack('h', 8001) might give me different
>> results depending on the machine it's running on?
>
> Right. I believe (but could be wrong) that "char" is defined
> to be one byte,
Yes, C defines "char" to be one byte, but it doesn't define the
size of a "byte" other than it's at least big enough to hold
one character (or something like that). In practice, a byte is
pretty much guaranteed to be at least 8 bits. But, on some
targets a "byte" is 16 bits, and on others a byte is 32 bits.
However, I'm not aware of any Python implementations on those
targets...
--
Grant Edwards grante Yow! Clear the laundromat!!
at This whirl-o-matic just had
visi.com a nuclear meltdown!!
More information about the Python-list
mailing list