473,386 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

char

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
Jan 9 '07 #1
6 12116
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.
Jan 9 '07 #2
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
Jan 9 '07 #3
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
Jan 9 '07 #4
On Tue, 09 Jan 2007 16:20:18 -0500, Ron Natalie <ro*@spamcop.net>
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
Jan 9 '07 #5
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
Jan 10 '07 #6
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.
Jan 10 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Christopher Benson-Manica | last post by:
I need a smart char * class, that acts like a char * in all cases, but lets you do some std::string-type stuff with it. (Please don't say to use std::string - it's not an option...). This is my...
5
by: Alex Vinokur | last post by:
"Richard Bos" <rlb@hoekstra-uitgeverij.nl> wrote in message news:4180f756.197032434@news.individual.net... to news:comp.lang.c > ben19777@hotmail.com (Ben) wrote: > > 2) Structure casted into an...
5
by: Sona | last post by:
I understand the problem I'm having but am not sure how to fix it. My code passes two char* to a function which reads in some strings from a file and copies the contents into the two char*s. Now...
2
by: Peter Nilsson | last post by:
In a post regarding toupper(), Richard Heathfield once asked me to think about what the conversion of a char to unsigned char would mean, and whether it was sensible to actually do so. And pete has...
5
by: jab3 | last post by:
(again :)) Hello everyone. I'll ask this even at risk of being accused of not researching adequately. My question (before longer reasoning) is: How does declaring (or defining, whatever) a...
12
by: GRoll35 | last post by:
I get 4 of those errors. in the same spot. I'll show my parent class, child class, and my driver. All that is suppose to happen is the user enters data and it uses parent/child class to display...
18
by: Pedro Pinto | last post by:
Hi there once more........ Instead of showing all the code my problem is simple. I've tried to create this function: char temp(char *string){ alterString(string); return string;
4
by: Paul Brettschneider | last post by:
Hello all, consider the following code: typedef char T; class test { T *data; public: void f(T, T, T); void f2(T, T, T);
16
by: s0suk3 | last post by:
This code #include <stdio.h> int main(void) { int hello = {'h', 'e', 'l', 'l', 'o'}; char *p = (void *) hello; for (size_t i = 0; i < sizeof(hello); ++i) {
29
by: Kenzogio | last post by:
Hi, I have a struct "allmsg" and him member : unsigned char card_number; //16 allmsg.card_number
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.