Path: csiph.com!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Tim Rentsch
Newsgroups: comp.lang.c++
Subject: Re: C++20 concepts rocks
Date: Sun, 06 Feb 2022 02:16:35 -0800
Organization: A noiseless patient Spider
Lines: 49
Message-ID: <86sfswjo58.fsf@linuxsc.com>
References: <87k0easj5d.fsf@bsb.me.uk> <86a6f5lq76.fsf@linuxsc.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="a80c60510ddf69c3dc6a890da3a37a42"; logging-data="31089"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+i36PHS8Zd/cz0LEECG3FfR6qOq0M95KE="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:u1AWvfr4SqtsP/hAdIpXMucyqzA= sha1:dt6VmKkL1g2huyvaYA4ZTZbRqD8=
Xref: csiph.com comp.lang.c++:82932
"Alf P. Steinbach" writes:
> On 5 Feb 2022 08:37, Tim Rentsch wrote:
>
>> "Alf P. Steinbach" writes:
>>
>>> On 4 Feb 2022 17:15, Ben Bacarisse wrote:
>>
>> [...]
>>
>>>> template
>>>> requires is_same_v>>> basic_string>>> typename StringType::traits_type,
>>>> typename StringType::allocator_type>>
>>>> StringType formatClockCycles(uint64_t clockCycles)
>>>> {
>>>> char result[28], *ep = (&result)[1];
>>>> do {
>>>> sprintf(ep - 4, "%03lu", clockCycles % 1000);
>>>> if (ep != (&result)[1]) ep[-1] = '.';
>>>> ep -= 4;
>>>> } while (clockCycles /= 1000);
>>>> while (*ep == '0' && ep[1]) ep++;
>>>> return ep;
>>>> }
>>>>
>>>> (the appropriate comment on the 28 is left as an exercise to the reader!)
>>>
>>> Nice, but I believe it's formal UB to move a pointer to `char` from
>>> beyond an array into the array, and dereference it.
>>>
>>> The C committee wrote a rationale for their earlier decision to make
>>> it so, instead of admitting that it was bludner. Uh, blunder. I
>>> don't recall who provided that information, but someone in this
>>> group.
>>
>> I suspect that you either are misremembering or have misunderstood.
>> Usage patterns like that seen above are defined behavior in C,
>> because they were in common use for at least 10 years before the
>> first C standard. It would be unthinkable for WG14 to have turned
>> it into undefined behavior.
>
> The "unthinkable" is why I maintain that it was originally a blunder,
> not intentional.
After reading some of your other comments elsethread, I now see
the difficulty: your earlier comments didn't clearly explain
what the issue is that you wanted to point out.