Rocksolid Light

Welcome to Rocksolid Light

mail  files  register  newsreader  groups  login

Message-ID:  

Measure twice, cut once.


devel / comp.arch / Re: On the pitfalls of C and UB: C23 seems to be even worse. :-(

SubjectAuthor
* Re: On the pitfalls of C and UB: C23 seems to be even worse. :-(Tim Rentsch
`* Re: On the pitfalls of C and UB: C23 seems to be even worse. :-(chrisq
 `- Re: On the pitfalls of C and UB: C23 seems to be even worse. :-(Tim Rentsch

1
Re: On the pitfalls of C and UB: C23 seems to be even worse. :-(

<86ilaexnet.fsf@linuxsc.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=33321&group=comp.arch#33321

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: tr.17687@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.arch
Subject: Re: On the pitfalls of C and UB: C23 seems to be even worse. :-(
Date: Thu, 20 Jul 2023 14:50:50 -0700
Organization: A noiseless patient Spider
Lines: 45
Message-ID: <86ilaexnet.fsf@linuxsc.com>
References: <u0f6gf$32irr$1@dont-email.me> <a533d5c4-8dca-44eb-ba43-bf38ab7f9f34n@googlegroups.com> <2023Apr4.073909@mips.complang.tuwien.ac.at> <u10pbe$259vd$1@dont-email.me> <u1132k$26kkr$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="3857442d865f8a7bff3454fde02b814b";
logging-data="3042472"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18eA40YixFHOhEtozhmw57H5/ltak+cgbE="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:UgznH4/tjwXjvPUlaDxCCw7H5EA=
sha1:PeOATrQRdjIhS+DiE9XeyN8cPsU=
 by: Tim Rentsch - Thu, 20 Jul 2023 21:50 UTC

Terje Mathisen <terje.mathisen@tmsw.no> writes:

> David Brown wrote:
>
>> On 04/04/2023 07:39, Anton Ertl wrote:
>>
>>> One reason for comparing pointers is if you want to implement
>>> memmove(), as discussed in the article.
>>
>> memmove(), and other standard library functions, are part of the
>> implementation. They were traditionally implemented in assembly,
>> and only later in C. But as part of the implementation, they can
>> use features that are implementation-specific - there was never any
>> need or intention that such functions should be implementable in
>> portable standards-compliant C. The language never had any need to
>> support writing an efficient memmove() in C - it gave you a
>> ready-made memmove() function so that implementing it yourself is
>> not necessary.
>
> Is pointer comparison implementation defined (ID) or UB?

Any two pointers (including null pointers) may be compared for
equality or inequality. The result is well defined: either
they are the same, or they aren't, and the implementation has
nothing to say about it.

For relational comparisons, the two pointers must be pointers into
(or one past) the same array object. All other pointer pairs
(including either or both being a null pointer) fall into UB
if relationally compared.

> If it is ID, then I can write my own version of memmove() (or similar
> ops) on any given compiler, as long as I do it the way that particular
> compiler have defined it, right?
>
> If it is UB, then that's impossible, you have to step outside of the C
> standard to implement it, and do so in a way that makes it impossible
> for the compiler to discover that you have done so. :-)

This conclusion is wrong. It is possible to implement memmove() in
standard C using only well-defined comparisons. (I suppose I should
add that some people would object based on the belief that the means
of doing so is horrible, which I don't necessarily share, but either
way I still think it's worth pointing out that it's possible, and
even feasible.)

Re: On the pitfalls of C and UB: C23 seems to be even worse. :-(

<u9ccv0$2t51r$2@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=33333&group=comp.arch#33333

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: devzero@nospam.com (chrisq)
Newsgroups: comp.arch
Subject: Re: On the pitfalls of C and UB: C23 seems to be even worse. :-(
Date: Thu, 20 Jul 2023 22:37:20 +0000
Organization: A noiseless patient Spider
Lines: 61
Message-ID: <u9ccv0$2t51r$2@dont-email.me>
References: <u0f6gf$32irr$1@dont-email.me>
<a533d5c4-8dca-44eb-ba43-bf38ab7f9f34n@googlegroups.com>
<2023Apr4.073909@mips.complang.tuwien.ac.at> <u10pbe$259vd$1@dont-email.me>
<u1132k$26kkr$1@dont-email.me> <86ilaexnet.fsf@linuxsc.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 20 Jul 2023 22:37:20 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="fabc0a67654ff25cd7b0b1a12db3ee86";
logging-data="3052603"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19I6h361dhW7qiZKlZ2oaVV"
User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:102.0) Gecko/20100101
Thunderbird/102.11.2
Cancel-Lock: sha1:4g64Vdran7OS2vxYjxcCexndPts=
In-Reply-To: <86ilaexnet.fsf@linuxsc.com>
Content-Language: en-US
 by: chrisq - Thu, 20 Jul 2023 22:37 UTC

On 7/20/23 21:50, Tim Rentsch wrote:
> Terje Mathisen <terje.mathisen@tmsw.no> writes:
>
>> David Brown wrote:
>>
>>> On 04/04/2023 07:39, Anton Ertl wrote:
>>>
>>>> One reason for comparing pointers is if you want to implement
>>>> memmove(), as discussed in the article.
>>>
>>> memmove(), and other standard library functions, are part of the
>>> implementation. They were traditionally implemented in assembly,
>>> and only later in C. But as part of the implementation, they can
>>> use features that are implementation-specific - there was never any
>>> need or intention that such functions should be implementable in
>>> portable standards-compliant C. The language never had any need to
>>> support writing an efficient memmove() in C - it gave you a
>>> ready-made memmove() function so that implementing it yourself is
>>> not necessary.
>>
>> Is pointer comparison implementation defined (ID) or UB?
>
> Any two pointers (including null pointers) may be compared for
> equality or inequality. The result is well defined: either
> they are the same, or they aren't, and the implementation has
> nothing to say about it.
>
> For relational comparisons, the two pointers must be pointers into
> (or one past) the same array object. All other pointer pairs
> (including either or both being a null pointer) fall into UB
> if relationally compared.
>
>> If it is ID, then I can write my own version of memmove() (or similar
>> ops) on any given compiler, as long as I do it the way that particular
>> compiler have defined it, right?
>>
>> If it is UB, then that's impossible, you have to step outside of the C
>> standard to implement it, and do so in a way that makes it impossible
>> for the compiler to discover that you have done so. :-)
>
> This conclusion is wrong. It is possible to implement memmove() in
> standard C using only well-defined comparisons. (I suppose I should
> add that some people would object based on the belief that the means
> of doing so is horrible, which I don't necessarily share, but either
> way I still think it's worth pointing out that it's possible, and
> even feasible.)

Programming in C or speaking natural language is fundamentally
about communication. If you want to be sure that the receiver
understands what you are saying, speak clearly and make no
assumptions about the receiver's knowledge.

Always program a strict subset of C here, no clever stuff
and most of it works first time, apart from typos. Saves
so much time in the long run. Can't be bothered doing
it right to start is the reason why we have so much bad code
to put up with...

Chris

Re: On the pitfalls of C and UB: C23 seems to be even worse. :-(

<86edkzt72l.fsf@linuxsc.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=33419&group=comp.arch#33419

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: tr.17687@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.arch
Subject: Re: On the pitfalls of C and UB: C23 seems to be even worse. :-(
Date: Sun, 23 Jul 2023 00:34:10 -0700
Organization: A noiseless patient Spider
Lines: 26
Message-ID: <86edkzt72l.fsf@linuxsc.com>
References: <u0f6gf$32irr$1@dont-email.me> <a533d5c4-8dca-44eb-ba43-bf38ab7f9f34n@googlegroups.com> <2023Apr4.073909@mips.complang.tuwien.ac.at> <u10pbe$259vd$1@dont-email.me> <u1132k$26kkr$1@dont-email.me> <86ilaexnet.fsf@linuxsc.com> <u9ccv0$2t51r$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="978ba9513973d7ae87a57600d2a2537b";
logging-data="215363"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19qwM1DUoecud2yocxhhFnca8uUBLzGXtE="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:9nlSGMHiOyfaMY4D+EkAOMl+lSg=
sha1:F2es1tyJ2q42O3kEfI+3zurHI+s=
 by: Tim Rentsch - Sun, 23 Jul 2023 07:34 UTC

chrisq <devzero@nospam.com> writes:

> On 7/20/23 21:50, Tim Rentsch wrote:

[regarding pointer comparison and memmove()]

>> It is possible to implement memmove() in standard C using only
>> well-defined comparisons. (I suppose I should add that some
>> people would object based on the belief that the means of doing
>> so is horrible, which I don't necessarily share, but either way I
>> still think it's worth pointing out that it's possible, and even
>> feasible.)
>
> Programming in C or speaking natural language is fundamentally
> about communication. If you want to be sure that the receiver
> understands what you are saying, speak clearly and make no
> assumptions about the receiver's knowledge.
>
> Always program a strict subset of C here, no clever stuff
> and most of it works first time, apart from typos. Saves
> so much time in the long run. Can't be bothered doing
> it right to start is the reason why we have so much bad code
> to put up with...

I don't necessarily agree with your advice, but whether
I do or not has no bearing on my comments.

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor