Is wchar_t guaranteed to be larger than char?

M

Mark A. Gibbs

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/[email protected]/
(temporary website)
 
J

John Carson

Mark A. Gibbs said:
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.
 

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,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top