Path: csiph.com!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Tim Rentsch
Newsgroups: comp.lang.c++
Subject: Re: Is this really necessary
Date: Sat, 07 Aug 2021 12:59:02 -0700
Organization: A noiseless patient Spider
Lines: 19
Message-ID: <86im0h2fi1.fsf@linuxsc.com>
References:
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="0a1d8104bbc0e7f8706fc1dabce7c8e9"; logging-data="18105"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+SwtWeXSsk5q18bVZkC2gUzPTwGp6uttU="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:MMu02CZEAKAh5p/HBaHS8JRU5Pg= sha1:X862V6DQH5twbKw43KqIXWqtk0w=
Xref: csiph.com comp.lang.c++:80791
Richard Damon writes:
> On 6/5/21 9:06 AM, Bonita Montero wrote:
>
>>> No. Subtraction of pointers is defined as the difference in their
>>> indexes within a single array.
>>
>> That coudn't be true because you can cast any pointer-pair
>> to char *, subtract them and use the difference for memcpy().
>
> Actually it is true. Char (and its relatives) do have a few special
> cases, as Any pointer is allowed to be converted into a pointer to char
> and back and still be used. Also I believe that any object can be
> treated as an array of char. So you can do the conversion to char and
> subtract for two pointers in the same object.
In C the difference of two pointers might not work, in particular
if the result doesn't fit in ptrdiff_t. I don't know if that
rule is different in C++.