Path: csiph.com!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c++ Subject: Re: Is this really necessary Date: Sun, 06 Jun 2021 16:10:15 -0700 Organization: None to speak of Lines: 28 Message-ID: <87r1hevbc8.fsf@nosuchdomain.example.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: reader02.eternal-september.org; posting-host="da0ef0006e1a2be3c584df7adb5e6866"; logging-data="24247"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX185k+s76jfbYPTGtaBA+fc3" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) Cancel-Lock: sha1:Qmn0WCRZaczBIyuRYZn3tR9nfsk= sha1:B9SIy87x/nYO4UCFcbVGZOrOOfw= Xref: csiph.com comp.lang.c++:80202 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. I believe there is. Without that limitation, the offsetof macro wouldn't work. > As an example, with Intel 386 you could have a 16-bit program working > simultaneously with at least 4 different 64 kB segments, which might > have been fully separate in the physical memory. Good luck with > forming a difference of pointers in a 16-bit size_t variable when the > segments are more than 64kB separate in the physical memory! -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com Working, but not speaking, for Philips Healthcare void Void(void) { Void(); } /* The recursive call of the void */