Path: csiph.com!aioe.org!T82FeZt+ua9clnYoA1RLIQ.user.46.165.242.91.POSTED!not-for-mail From: MrSpud_85yGi2@1ahbfz.gov Newsgroups: comp.lang.c++ Subject: Re: Is this really necessary Date: Sun, 8 Aug 2021 09:18:47 -0000 (UTC) Organization: Aioe.org NNTP Server Message-ID: References: <86im0h2fi1.fsf@linuxsc.com> Injection-Info: gioia.aioe.org; logging-data="44284"; posting-host="T82FeZt+ua9clnYoA1RLIQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org"; X-Notice: Filtered by postfilter v. 0.9.2 Xref: csiph.com comp.lang.c++:80795 On Sat, 07 Aug 2021 12:59:02 -0700 Tim Rentsch wrote: >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++. Huh? Any type that can be used to hold a pointer address can also be used to hold the difference of 2 pointers. If the difference will be negative then simply invert it.