char

C

Chameleon

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
 
R

Ron Natalie

Chameleon said:
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.
 
?

=?ISO-8859-15?Q?Juli=E1n?= Albo

Chameleon said:
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.
 
V

Victor Bazarov

Ron said:
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
 
J

Jack Klein

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.
 
?

=?ISO-8859-15?Q?Juli=E1n?= Albo

Jack said:
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?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top