Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > sizeof(char)

Reply
Thread Tools

sizeof(char)

 
 
nsgi_2004
Guest
Posts: n/a
 
      06-03-2004
I have a C book that says the sizeof a char is one byte. Is this true for
C++?


 
Reply With Quote
 
 
 
 
qWake
Guest
Posts: n/a
 
      06-03-2004
"nsgi_2004" <(E-Mail Removed)> 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.


 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      06-03-2004
"nsgi_2004" <(E-Mail Removed)> 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


 
Reply With Quote
 
David Harmon
Guest
Posts: n/a
 
      06-03-2004
On Wed, 2 Jun 2004 20:37:24 -0700 in comp.lang.c++, "nsgi_2004"
<(E-Mail Removed)> 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.

 
Reply With Quote
 
Michiel Salters
Guest
Posts: n/a
 
      06-04-2004
"nsgi_2004" <(E-Mail Removed)> 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
 
Reply With Quote
 
red floyd
Guest
Posts: n/a
 
      06-04-2004
Michiel Salters wrote:

> "nsgi_2004" <(E-Mail Removed)> 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".
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments