Re: to calculate bitsize of a byte



stathis gotsis wrote:
"slebetman@xxxxxxxxx" <slebetman@xxxxxxxxx> wrote in message
news:1140585624.578406.37500@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hmm.. this is slowly getting to be off-topic in c.l.c. Anyway...

A byte does not refer to a word. A machine word in hardware does indeed
usually correspond to an int. A byte is usually defined as the smallest
addressible unit of memory for an architecture whereas a word is
usually defined as the native register size of the architecture
(whatever that means).

The smallest addressible memory may not always be 8 bits. And on
machines where this is smaller than 8 bits (for example 6 bits was once
very common) the C standard requires chars to be at least 8 bits. Hence
the C standard requires that on such machines two bytes be used to
represent a char. It is also common to find modern machines,
particularly DSPs, where the machine byte is 32 bits. On such machines
it is not possible to address smaller than 32 bit values (you can
access individual octets though by masking and shifting but you cannot
address individual octets).

Based on what you said i came to the assumption that CHAR_BIT is the minimum
multiple of the number of bits in the machine byte which is equal or greater
than 8. So, given the CHAR_BIT value, one can find one or two numbers, one
of which will be the machine byte size. That means that the machine byte can
be roughly determined through C.

Hmm.. But what about a machine with 9 bit bytes where CHAR_BIT is 8
(the C compiler simply ignores the most significant bit)? I believe
that the standard doesn't allow padding bits in char but I think in
this case the most significant bit is not a padding bit, it is simply
ignored by the compiler author. In this case a string of chars will
still be contiguous from the point of view of C but you won't be able
to ever find out the size of the machine byte from C.

I'm not so sure about how conformant is such an implementation. Any
standard experts here think it's valid?

.



Relevant Pages

  • Re: Storage & Passing of "Typed" data
    ... I don't think we have to worry about the "average" compiler here. ... For example, the Fortran standard ... dictinctions between virtual and real memory layout. ... padding would be allowed. ...
    (comp.lang.fortran)
  • Re: to calculate bitsize of a byte
    ... very common) the C standard requires chars to be at least 8 bits. ... represent a char. ... this case the most significant bit is not a padding bit, ... ignored by the compiler author. ...
    (comp.lang.c)
  • Re: Order of data member in a structure
    ... >> Only thing to be concerned about is padding bits. ... > time anyone has said that the compiler can use that ... > POD types (unless they happen to be char or arrays of ... What I'm getting it is that there's nothing in the Standard ...
    (comp.lang.cpp)
  • Re: Is C99 the final C? (some suggestions)
    ... > that someone will try compile their stuff on an old compiler. ... > because the ANSI standard obsoleted them, and everyone picked up the ANSI ... fixed by using another language. ... >>are multiplying two expressions of the widest type supported by your ...
    (comp.lang.c)
  • Re: Statement on Schildt submitted to wikipedia today
    ... to working programmers and more with being "right all the time, ... so that compiler developers could be shed ... The major corporate interests were compiler developers, ... processors, committed to standard division semantics, and otherwise ...
    (comp.lang.c.moderated)