Re: multi bytes character - how to make it defined behavior?

Liste des GroupesRevenir à l c 
Sujet : Re: multi bytes character - how to make it defined behavior?
De : thiago.adams (at) *nospam* gmail.com (Thiago Adams)
Groupes : comp.lang.c
Date : 14. Aug 2024, 13:41:01
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v9i54d$e3c6$1@dont-email.me>
References : 1 2 3
User-Agent : Mozilla Thunderbird
On 13/08/2024 21:33, Keith Thompson wrote:
Bart<bc@freeuk.com>  writes:
[...]
What exactly do you mean by multi-byte characters? Is it a literal
such as 'ABCD'?
>
I've no idea what C makes of that,
It's a character constant of type int with an implementation-defined
value.  Read the section on "Character constants" in the C standard
(6.4.4.4 in C17).
 (With gcc, its value is 0x41424344, but other compilers can and do
behave differently.)
 We discussed this at some length several years ago.
 [...]
"An integer character constant has type int. The value of an integer character constant containing
a single character that maps to a single value in the literal encoding (6.2.9) is the numerical value
of the representation of the mapped character in the literal encoding interpreted as an integer.
The value of an integer character constant containing more than one character (e.g. ’ab’), or
containing a character or escape sequence that does not map to a single value in the literal encoding,
is implementation-defined. If an integer character constant contains a single character or escape
sequence, its value is the one that results when an object with type char whose value is that of the
single character or escape sequence is converted to type int."
I am suggesting the define this:
"The value of an integer character constant containing more than one character (e.g. ’ab’), or containing a character or escape sequence that does not map to a single value in the literal encoding, is implementation-defined."
How?
First, all source code should be utf8.
Then I am suggesting we first decode the bytes.
For instance, '×' is encoded with 195 and 151. We consume these 2 bytes and the utf8 decoded value is 215.
Then this is the defined behavior
static_assert('×' == 215)
In case we have 'ab' for instance:
Fist we decode 'a' 97 then 'b' 98. We consume one byte each.
Then we have two characters. In this case we do
256 * 'a' + 'b' = 256*97+98= 24930
static_assert('ab' == 24930)
I believe this static_assert('ab' == 24930) matches the way it is used today.
In case the value is bigger than MAX_INT I think it should be unsigned int.
Why?
Adding fixes on top of fixes make the language bigger and complex.
Like adding U'' L'' u8'' etc.
In my source code I use only utf8, everything just works without any u8"" etc.

Date Sujet#  Auteur
13 Aug 24 * multi bytes character - how to make it defined behavior?19Thiago Adams
14 Aug 24 +* Re: multi bytes character - how to make it defined behavior?16Bart
14 Aug 24 i`* Re: multi bytes character - how to make it defined behavior?15Keith Thompson
14 Aug 24 i `* Re: multi bytes character - how to make it defined behavior?14Thiago Adams
14 Aug 24 i  `* Re: multi bytes character - how to make it defined behavior?13Bart
14 Aug 24 i   +* Re: multi bytes character - how to make it defined behavior?11Thiago Adams
14 Aug 24 i   i+* Re: multi bytes character - how to make it defined behavior?9Bart
14 Aug 24 i   ii`* Re: multi bytes character - how to make it defined behavior?8Thiago Adams
14 Aug 24 i   ii +- Re: multi bytes character - how to make it defined behavior?1Thiago Adams
14 Aug 24 i   ii +* Re: multi bytes character - how to make it defined behavior?5Bart
14 Aug 24 i   ii i`* Re: multi bytes character - how to make it defined behavior?4Thiago Adams
14 Aug 24 i   ii i `* Re: multi bytes character - how to make it defined behavior?3Bart
14 Aug 24 i   ii i  `* Re: multi bytes character - how to make it defined behavior?2Thiago Adams
14 Aug 24 i   ii i   `- Re: multi bytes character - how to make it defined behavior?1Bart
15 Aug 24 i   ii `- Re: multi bytes character - how to make it defined behavior?1Lawrence D'Oliveiro
15 Aug 24 i   i`- Re: multi bytes character - how to make it defined behavior?1Lawrence D'Oliveiro
15 Aug 24 i   `- Re: multi bytes character - how to make it defined behavior?1Lawrence D'Oliveiro
14 Aug 24 +- Re: multi bytes character - how to make it defined behavior?1Ben Bacarisse
14 Aug 24 `- Re: multi bytes character - how to make it defined behavior?1Richard Damon

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal