Re: Abstraction layer between C and CPU

From: Mike Wahler (mkwahler_at_mkwahler.net)
Date: 01/21/05


Date: Fri, 21 Jan 2005 19:36:50 GMT


"Jonathan Burd" <jonathan.burd@REMOVEMEgmail.com> wrote in message
news:35c55gF4lkgjsU1@individual.net...
> Thomas Stegen wrote:
> > Mike Wahler wrote:
> >
> >> "E. Robert Tisdale" <E.Robert.Tisdale@jpl.nasa.gov> wrote in message
> >> news:csq1nd$dht$1@nntp1.jpl.nasa.gov...
> >
> > [snip usual char byte 8 bit not 8 bit discussion]
> >
> > Semi OT perhaps but...
> >
> > Outside a C perspective, didn't IBM first coin the term byte to
> > refer to 8 bit entities? As far as I know machines such as the
> > pdp-11 (I think) had 9 bit entities, but never used the term byte.
> >
> > It is also clear though that in a C context byte does not mean
> > this. It is also clear that one should establish a context,
> > implicitly or explicitly, when discussing bytes with anyone.
> > Are we in the C locale, or in the mere mortals locale?
> >
> > Here in comp.lang.c thw context should be clear to everyone.
> >
>
> Perhaps, using the term ``octet" for a group of 8 bits would be
> much better. A byte may be an octet and is the most basic
> addressable unit in an execution environment. Therefore, a byte,
> according to this definition, may also be 4 bits.

A 'C byte' must have at least eight bits.

>
> To reply to the original context, C does not have
> a ``byte" data type. In C, a char contains, at least, enough
> bits to represent any element of the basic character set.
> A char may at least be a byte or higher.

IOW a char must fit in a byte.

>
> I don't see how you can safely assume a char to contain at least
> 8 bits. The standard doesn't say so explicitly.

I'll let you decide if this is explicit or not:

  ISO/IEC 9899:1999 (E)

  5.2.4.2.1 Sizes of integer types <limits.h>

1 The values given below shall be replaced by constant expressions
  suitable for use in #if preprocessing directives. Moreover, except
  for CHAR_BIT and MB_LEN_MAX, the following shall be replaced by
  expressions that have the same type as would an expression that
  is an object of the corresponding type converted according to the
  integer promotions. Their implementation-defined values shall be
  equal or greater in magnitude (absolute value) to those shown, with
  the same sign.

  -- number of bits for smallest object that is not a bit-field (byte)
     CHAR_BIT 8

-Mike



Relevant Pages

  • Re: Abstraction layer between C and CPU
    ... It is also clear that one should establish a context, ... >> Are we in the C locale, or in the mere mortals locale? ... > bits to represent any element of the basic character set. ... > A char may at least be a byte or higher. ...
    (comp.lang.c)
  • Re: How to print a string of unsigned chars?
    ... have the same representation and alignment requirements as a pointer ... Although it isn't explicit, I'm sure that 'a' ... character type, and thus pointers to all three flavors of char must be ... and do not expect to encounter one. ...
    (comp.lang.c)
  • Re: memory leak?
    ... when he could instead use the more robust C++ container classes like ... explicit BYTE identifier is used, instead of 'char' (I don't know if the C++ ...
    (microsoft.public.vc.mfc)
  • Re: Abstraction layer between C and CPU
    ... It is also clear that one should establish a context, ... using the term ``octet" for a group of 8 bits would be ... bits to represent any element of the basic character set. ... A char may at least be a byte or higher. ...
    (comp.lang.c)
  • Re: I need HELP!!!
    ... char ch; ... leave context in your post. ... quote what you are replying to ...
    (comp.lang.c)