Path: csiph.com!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Tim Rentsch
Newsgroups: comp.lang.c
Subject: Re: Simple(?) Unicode questions
Date: Wed, 24 Jan 2024 20:38:26 -0800
Organization: A noiseless patient Spider
Lines: 79
Message-ID: <86ede6do3h.fsf@linuxsc.com>
References: <86wmt2tx80.fsf@linuxsc.com> <87bkadx5s6.fsf@nosuchdomain.example.com> <8634urkiyx.fsf@linuxsc.com> <87v87nbqbk.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="233ecb52840d096af87a0e664f2c83b5"; logging-data="2297708"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+7r/IAu5lVC4QHmhpqxQ9xjD/5HIudlXY="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:3g17XEQKgFY9D8udVwDBBwsUX9A= sha1:SLiNPdx8zMLGRO8bXnk35WF0hqY=
Xref: csiph.com comp.lang.c:380883
Keith Thompson writes:
> Tim Rentsch writes:
>
>> Keith Thompson writes:
>>
>>> Tim Rentsch writes:
>>>
>>>> Lew Pitcher writes:
>>>>
>>>>> On Wed, 13 Dec 2023 11:05:45 +0800, spender wrote:
>>>>>
>>>>>> printf("%c",ch), the ch must <0xFF, <255
>>>>>
>>>>> Not quite.
>>>>> 1) ch /must/ represent an integer value.
>>>>
>>>> More specifically, it must have a type that is or promotes
>>>> to int, or a type that is or promotes to unsigned int, with
>>>> a value that is in the common range of int and unsigned int.
>>>
>>> Not quite. "If no l length modifier is present, the int argument
>>> is converted to an unsigned char, and the resulting character is
>>> written." For example printf("%c", -193) is equivalent to
>>> printf("%c", 63), which assuming an ASCII-based character set will
>>> print '?'.
>>
>> The rule for arguments to printf() is the same as the rule for
>> accessing variadic arguments using va_arg(). That has always
>> been true, although not expressed clearly in early versions of
>> the C standard. Fortunately that shortcoming is addressed in
>> the upcoming C23 (is it still not yet ratified?): in N3096,
>> paragraph 9 in section 7.23.6.1 says in part
>>
>> fprintf shall behave as if it uses va_arg with a type
>> argument naming the type resulting from applying the
>> default argument promotions to the type corresponding
>> to the conversion specification [...]
>>
>> and the rule for va_arg (in 7.16.1.1 p2) says in part
>>
>> one type is a signed integer type, the other type is
>> the corresponding unsigned integer type, and the value
>> is representable in both types
>>
>> So supplying an unsigned int argument is okay, provided of
>> course the value is in the range of values of signed int.
>
> Re-reading what you wrote, I think I misunderstood your intent (and I
> think what you wrote was ambiguous).
>
> "%c" specifies an int argument.
>
> You wrote:
>
> More specifically, it must have a type that is or promotes to int,
> or a type that is or promotes to unsigned int, with a value that is
> in the common range of int and unsigned int.
>
> I read that as:
>
> More specifically,
> (it must have a type that is or promotes to int, or a type that is
> or promotes to unsigned int),
> with a value that is in the common range of int and unsigned int.
>
> which would incorrectly imply that a negative int value is not allowed.
>
> It's now clear to me that you meant was:
>
> More specifically,
> (it must have a type that is or promotes to int),
> or
> (a type that is or promotes to unsigned int, with a value that is in
> the common range of int and unsigned int).
>
> I agree with that.
Right. Sorry for the confusion.