Path: csiph.com!aioe.org!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: Mon, 07 Jun 2021 09:19:19 -0700
Organization: A noiseless patient Spider
Lines: 23
Message-ID: <86tum9d4vs.fsf@linuxsc.com>
References:
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="e6c86ac6dad3f265ee72dc540c206688"; logging-data="31099"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX190rXDuOmT3Yf5aksB9rxMtbxS2AutF3FQ="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:mQ8K4ycpgroXvxayd6t5P4+IW8A= sha1:b4ml9E99jfa8PpApkNA5JxDjE6c=
Xref: csiph.com comp.lang.c++:80216
Paavo Helde writes:
> 05.06.2021 16:06 Bonita Montero kirjutas:
>
>>> 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().
>
> This holds only for linear memory model. While this is a dominant
> memory model nowadays, the C++ language is old enough to take also
> other memory models (like segmented ones) into account. In segmented
> memory models, pointer arithmetic only works in a single segment, and
> accordingly the arrays are limited to a single segment. There is no
> such limitation for struct members.
In C there is, because any object can be treated as an array
of character type, and that includes structs.
In C++ the rules are so complicated that no one knows whether
that reasoning applies, so the safest course of action is not
to use C++ on machines that use segmentation.