Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Integral promotions for char16_t, char32_t, and wchar_t

17 views
Skip to first unread message

Nikolay Ivchenkov

unread,
Aug 24, 2010, 2:08:54 AM8/24/10
to
According to N3092 - 4.5/2,

"A prvalue of type char16_t, char32_t, or wchar_t (3.9.1) can be
converted to a prvalue of the first of the following types that can
represent all the values of its underlying type: int, unsigned int,
long int, unsigned long int, long long int, or unsigned long long int.
If none of the types in that list can represent all the values of its
underlying type, a prvalue of type char16_t, char32_t, or wchar_t can
be converted to a prvalue of its underlying type."

I can't imagine an implementation where 'unsigned int' cannot
represent all values of 'char16_t' or where 'unsigned long int' cannot
represent all values of 'char32_t'. According to N3092 - 18.3.2, 1.1/2
& C99 - 5.2.4.2.1, 'unsigned int' shall represent all values of the
range 0..65535 and 'unsigned long int' shall represent all values of
the range 0..4294967295. It's also difficult to imagine a character
set which cannot be represented by a set of codes
0..18446744073709551615 ('unsigned long long int' shall be able to
hold any value of this range). So, what is the point of the second
quoted sentence?

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Daniel Krügler

unread,
Aug 24, 2010, 4:57:27 PM8/24/10
to
On 24 Aug., 08:08, Nikolay Ivchenkov <ts...@mail.ru> wrote:
> According to N3092 - 4.5/2,
>
> "A prvalue of type char16_t, char32_t, or wchar_t (3.9.1) can be
> converted to a prvalue of the first of the following types that can
> represent all the values of its underlying type: int, unsigned int,
> long int, unsigned long int, long long int, or unsigned long long int.
> If none of the types in that list can represent all the values of its
> underlying type, a prvalue of type char16_t, char32_t, or wchar_t can
> be converted to a prvalue of its underlying type."
>
> I can't imagine an implementation where 'unsigned int' cannot
> represent all values of 'char16_t' or where 'unsigned long int' cannot
> represent all values of 'char32_t'.

Neither do I. The types "unsigned int|long" either satisfy the
requirements
of uint_least16|32_t exactly or they have a wider value
representation.

> According to N3092 - 18.3.2, 1.1/2
> & C99 - 5.2.4.2.1, 'unsigned int' shall represent all values of the
> range 0..65535 and 'unsigned long int' shall represent all values of
> the range 0..4294967295. It's also difficult to imagine a character
> set which cannot be represented by a set of codes
> 0..18446744073709551615 ('unsigned long long int' shall be able to
> hold any value of this range). So, what is the point of the second
> quoted sentence?

It just provides rules that are independent on the more indirect
requirements based on <climits>, that are imposed on by the
environment requirements. Usually, the core language attempts
to be independent on such things. The current core rules should
just work, independent on the special constraints on UINT_MAX
and ULONG_MAX and are more robust against possible wording
changes in other locations of the Standard.

HTH & Greetings from Bremen,

Daniel Krügler

0 new messages