sizeof(char)

Discussion in 'C++' started by nsgi_2004, Jun 3, 2004.

  1. nsgi_2004

    nsgi_2004 Guest

    I have a C book that says the sizeof a char is one byte. Is this true for
    C++?
     
    nsgi_2004, Jun 3, 2004
    #1
    1. Advertising

  2. nsgi_2004

    qWake Guest

    "nsgi_2004" <> wrote in message
    news:X1xvc.42929$mm1.41139@fed1read06...
    > I have a C book that says the sizeof a char is one byte. Is this true for
    > C++?


    Yes.
     
    qWake, Jun 3, 2004
    #2
    1. Advertising

  3. "nsgi_2004" <> wrote...
    > I have a C book that says the sizeof a char is one byte. Is this true for
    > C++?


    sizeof(char) is always 1, yes. 'char' and 'byte' are synonyms in
    both C and C++ when sizes are concerned.

    V
     
    Victor Bazarov, Jun 3, 2004
    #3
  4. nsgi_2004

    David Harmon Guest

    On Wed, 2 Jun 2004 20:37:24 -0700 in comp.lang.c++, "nsgi_2004"
    <> wrote,
    >I have a C book that says the sizeof a char is one byte. Is this true for
    >C++?


    Yes. Note that a byte or char must be AT LEAST 8 bits in size,
    but can be any number larger.
     
    David Harmon, Jun 3, 2004
    #4
  5. "nsgi_2004" <> wrote in message news:<X1xvc.42929$mm1.41139@fed1read06>...
    > I have a C book that says the sizeof a char is one byte. Is this true for
    > C++?


    Yes, because C++ redefines byte to mean the size of a char. It's not
    always the 8-bit thingy you might expect. This is shared between C
    and C++, It's relevant e.g. for some DSP chips inside cellphones
    that have 32 bits per byte. Now, those are programmed in C not C++,
    but C++ felt no need to differ from C here. If anyone writes a
    C++ compiler for such things, they can still use the same 32-bit
    char.

    Regards,
    Michiel Salters
     
    Michiel Salters, Jun 4, 2004
    #5
  6. nsgi_2004

    red floyd Guest

    Michiel Salters wrote:

    > "nsgi_2004" <> wrote in message news:<X1xvc.42929$mm1.41139@fed1read06>...
    >
    >>I have a C book that says the sizeof a char is one byte. Is this true for
    >>C++?

    >
    >
    > Yes, because C++ redefines byte to mean the size of a char. It's not
    > always the 8-bit thingy you might expect. This is shared between C
    > and C++, It's relevant e.g. for some DSP chips inside cellphones
    > that have 32 bits per byte. Now, those are programmed in C not C++,
    > but C++ felt no need to differ from C here. If anyone writes a
    > C++ compiler for such things, they can still use the same 32-bit
    > char.
    >
    > Regards,
    > Michiel Salters


    Yep. If you want to specify an 8-bit quantity, you might want to follow
    the lead of the internet RFC guys and call it an "octet". sizeof(char)
    is 1. Period. Regardless of the actual number of bits in it. Just for
    reference, IIRC from my original K&R, one of the early C implementations
    was on a machine with 9-bit "bytes".
     
    red floyd, Jun 4, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Derek
    Replies:
    7
    Views:
    24,340
    Ron Natalie
    Oct 14, 2004
  2. M Welinder

    sizeof (char)(char)2

    M Welinder, Jul 26, 2004, in forum: C Programming
    Replies:
    10
    Views:
    517
    Kevin Bracey
    Jul 27, 2004
  3. lovecreatesbeauty
    Replies:
    1
    Views:
    1,061
    Ian Collins
    May 9, 2006
  4. davidb
    Replies:
    0
    Views:
    766
    davidb
    Sep 1, 2006
  5. davidb
    Replies:
    6
    Views:
    1,557
    Default User
    Sep 1, 2006
Loading...

Share This Page