Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > char

Reply
 
 
Chameleon
Guest
Posts: n/a
 
      01-09-2007
char is 1 byte length in standard c/c++?

I ask because short/int/long has not a specific length in bytes, but:
short is smaller or equal to int
int is smaller or equal to long
 
Reply With Quote
 
 
 
 
Ron Natalie
Guest
Posts: n/a
 
      01-09-2007
Chameleon wrote:
> char is 1 byte length in standard c/c++?


By definition. A char is exactly one byte in size because
that's how a byte in C++ is defined. However, it points out
one glaring problem in C and C++. Char serves double duty:
1. It's the native character size.
2. It's the smallest addressable unit of storage.

That means that you can't really use char's if you have 16 bit
native characters unless you want to give up the ability to
address on 8 bit boundaries. What makes this worse is that
C++ rots big time on wchar_t support. Many important interfaces
(filenames, program arguments) don't have any wide char interface.
>
> I ask because short/int/long has not a specific length in bytes, but:
> short is smaller or equal to int
> int is smaller or equal to long

Note that "bytes" is not any specific number of bits in C++.

There are practical lower limits on short and long (16 and 32 bits)
in addition to the char <= short <= int <= long.
 
Reply With Quote
 
 
 
 
=?ISO-8859-15?Q?Juli=E1n?= Albo
Guest
Posts: n/a
 
      01-09-2007
Chameleon wrote:

> char is 1 byte length in standard c/c++?


Yes, but the word byte has several usages depending on conext. In some
contexts it means minimal addressable unit, in some others it means 8 bits
(because is the same as the previous one in that context, of for other
reasons), and in standard C++ context it means the size of a char.

Then the size of char is 1 byte by definition, no matter if his bit size is
8, 16, 32 or whatever.

To avoid ambiguities is better to use the word octect to refer to an 8 bit
size, like Internet RFC documents do.

--
Salu2
 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      01-09-2007
Ron Natalie wrote:
> Chameleon wrote:
>> char is 1 byte length in standard c/c++?

>
> By definition. A char is exactly one byte in size because
> that's how a byte in C++ is defined. However, it points out
> one glaring problem in C and C++. Char serves double duty:
> 1. It's the native character size.
> 2. It's the smallest addressable unit of storage.
>
> That means that you can't really use char's if you have 16 bit
> native characters unless you want to give up the ability to
> address on 8 bit boundaries.


I honestly don't understand that statement. Could you please
elaborate?

> What makes this worse is [..]
>>
>> I ask because short/int/long has not a specific length in bytes, but:
>> short is smaller or equal to int
>> int is smaller or equal to long

> Note that "bytes" is not any specific number of bits in C++.


What about 'CHAR_BIT'? Is it not specific enough?

> [..]


V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


 
Reply With Quote
 
Jack Klein
Guest
Posts: n/a
 
      01-09-2007
On Tue, 09 Jan 2007 16:20:18 -0500, Ron Natalie <>
wrote in comp.lang.c++:

> Chameleon wrote:
> > char is 1 byte length in standard c/c++?

>
> By definition. A char is exactly one byte in size because
> that's how a byte in C++ is defined. However, it points out
> one glaring problem in C and C++. Char serves double duty:
> 1. It's the native character size.
> 2. It's the smallest addressable unit of storage.
>
> That means that you can't really use char's if you have 16 bit
> native characters unless you want to give up the ability to
> address on 8 bit boundaries. What makes this worse is that
> C++ rots big time on wchar_t support. Many important interfaces
> (filenames, program arguments) don't have any wide char interface.


In C and C++ implementations where chars have 16 (or 32) bits, exist
primarily on DSPs (Digital Signal Processors) that physically CAN'T
access memory in units smaller than the 16 or 32 bit machine words.

Typically they are used in embedded systems running in free-standing
environments where there aren't any filenames or program arguments,
anyway.

But if there was a hosted environment for a CHAR_BIT > 8 system, I am
quite sure that the underlying platform would find a way to deal with
these things, if necessary.

You'd be surprised how little difference 16 bit chars makes to code
designed and written with a little care.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
 
Reply With Quote
 
=?ISO-8859-15?Q?Juli=E1n?= Albo
Guest
Posts: n/a
 
      01-10-2007
Jack Klein wrote:

> You'd be surprised how little difference 16 bit chars makes to code
> designed and written with a little care.


So you must avoid to take too much care?

--
Salu2
 
Reply With Quote
 
Sumit Rajan
Guest
Posts: n/a
 
      01-10-2007
Chameleon wrote:
> char is 1 byte length in standard c/c++?



You may find the first six questions/answers interesting:
http://www.parashift.com/c++-faq-lit...sic-types.html

Regards,
Sumit.
 
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


Similar Threads
Thread Thread Starter Forum Replies Last Post
(const char *cp) and (char *p) are consistent type, (const char **cpp) and (char **pp) are not consistent lovecreatesbeauty C Programming 1 05-09-2006 08:01 AM
/usr/bin/ld: ../../dist/lib/libjsdombase_s.a(BlockGrouper.o)(.text+0x98): unresolvable relocation against symbol `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostre silverburgh.meryl@gmail.com C++ 3 03-09-2006 12:14 AM
char *fred; char * fred; char *fred; any difference? Ben Pfaff C Programming 5 01-17-2004 07:37 PM
The difference between char a[6] and char *p=new char[6] ? wwj C Programming 24 11-07-2003 05:27 PM
the difference between char a[6] and char *p=new char[6] . wwj C++ 7 11-05-2003 12:59 AM



Advertisments