Lies in education [was Re: The "loop and a half"]

Grant Edwards grant.b.edwards at gmail.com
Thu Oct 12 20:48:42 EDT 2017


On 2017-10-12, Steve D'Aprano <steve+python at pearwood.info> wrote:
> On Fri, 13 Oct 2017 02:06 am, Grant Edwards wrote:
>
>> It sure was an education the first I wrote C code for
>> a machine where
>> 
>> 1 == sizeof char == sizeof int == sizeof long == sizeof float == sizeof
>> double
>> 
>> All were 32 bits.
>
>
> Does that imply that on that machine 1 byte = 32 bits?

Maybe.  That depends on what you mean by "byte".  There is no such
thing as a "byte" in C.  The smallest addressable unit of memory in C
is a "char".  Nothing in C says that incrementing an address by 1 gets
you to the next 8-bit chunk of memory.

According to the "Byte" Wikipedia article:

   The size of the byte has historically been hardware dependent and
   no definitive standards existed that mandated the size -- byte-sizes
   from 1 to 48 bits are known to have been used in the past.

The IEEE standards use the word "octet" to refer to a an 8-bit chunk
of memory.  When working with an architecture with a 32-bit char, you
didn't use the word "byte" if you wanted to avoid confusion.

> I don't suppose you remember the name of the machine do you?

Texas Instruments TMS32C40.

It's pretty common on DSPs to have only a single size for all
datatypes.  The 'C40 as pretty high-end -- it had floating point.
Though I had to write routines to convert between IEE-754 and the
native 32-bit format when I wanted to exchange floating point data
with the outside world. :)

--
Grant








More information about the Python-list mailing list