Re: to calculate bitsize of a byte
- From: "slebetman@xxxxxxxxx" <slebetman@xxxxxxxxx>
- Date: 22 Feb 2006 16:58:42 -0800
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?
.
- Follow-Ups:
- Re: to calculate bitsize of a byte
- From: CBFalconer
- Re: to calculate bitsize of a byte
- From: Jordan Abel
- Re: to calculate bitsize of a byte
- References:
- to calculate bitsize of a byte
- From: david ullua
- Re: to calculate bitsize of a byte
- From: Rod Pemberton
- Re: to calculate bitsize of a byte
- From: david ullua
- Re: to calculate bitsize of a byte
- From: slebetman@xxxxxxxxx
- Re: to calculate bitsize of a byte
- From: stathis gotsis
- Re: to calculate bitsize of a byte
- From: Peter Nilsson
- Re: to calculate bitsize of a byte
- From: slebetman@xxxxxxxxx
- Re: to calculate bitsize of a byte
- From: Jordan Abel
- Re: to calculate bitsize of a byte
- From: slebetman@xxxxxxxxx
- Re: to calculate bitsize of a byte
- From: stathis gotsis
- to calculate bitsize of a byte
- Prev by Date: Re: GetWindowEx() looping question
- Next by Date: Re: to calculate bitsize of a byte
- Previous by thread: Re: to calculate bitsize of a byte
- Next by thread: Re: to calculate bitsize of a byte
- Index(es):
Relevant Pages
|