By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,421 Members | 1,053 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,421 IT Pros & Developers. It's quick & easy.

Is wchar_t guaranteed to be larger than char?

P: n/a
Good day,

I'm asking this just out of curiosity, but it just occurred to me to
reread the section on wchar_t (3.9.1.5), and unless I'm reading it
wrong, there is no guarantee that wchar_t is larger than char.

What I'm seeing is that it has to have the same characteristics as its
underlying type, which can be any integral type. The integral types are
bool, char (plain, signed, unsigned), short, int and long (signed and
unsigned, plus presumably long long) (3.9.1.7). So the underyling type
could be signed char?

--
Mark A. Gibbs (aka. Indi)
Administrator
#c++ on irc.Rizon.net

http://ca.geocities.com/in***@rogers.com/
(temporary website)

Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
"Mark A. Gibbs" <x_*********@rogers.com_x> wrote in message
news:Z9********************@rogers.com
Good day,

I'm asking this just out of curiosity, but it just occurred to me to
reread the section on wchar_t (3.9.1.5), and unless I'm reading it
wrong, there is no guarantee that wchar_t is larger than char.


Correct. There is also no guarantee that an int is larger than a char. Note
that a char could be, say, 32 bits.

Stroustrup (TC++PL, p.75) has this table:

1==sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long)

1 <= sizeof(bool) <= sizeof(long)

sizeof(char) <= sizeof(wchar_t) <= sizeof(long)

sizeof(float) <= sizeof(double) <= sizeof(long double)

sizeof(N) == sizeof(signed N) == sizeof(unsigned N)

where N is a char, short int, int or long int.

In addition, char is at least 8 bits, short at least 16 bits and long at
least 32 bits.

In terms of relative and absolute sizes, nothing else is guaranteed.
--
John Carson
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.