Path: csiph.com!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!news.uzoreto.com!aioe.org!T82FeZt+ua9clnYoA1RLIQ.user.46.165.242.91.POSTED!not-for-mail From: MrSpud_1dgrmf@dx58865qyrdw30lqllb.info Newsgroups: comp.lang.c++ Subject: Re: Is this really necessary Date: Mon, 9 Aug 2021 08:21:10 -0000 (UTC) Organization: Aioe.org NNTP Server Message-ID: References: <86im0h2fi1.fsf@linuxsc.com> Injection-Info: gioia.aioe.org; logging-data="30109"; 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++:80803 On Sun, 8 Aug 2021 15:04:52 -0000 (UTC) Juha Nieminen wrote: >James Kuyper wrote: >> On 8/8/21 5:18 AM, MrSpud_85yGi2@1ahbfz.gov wrote: >> In the C standard, 7.20.1.4p1 describes intptr_t and uintptr_t, and says >> "These types are optional". A fully conforming implementation may have >> pointers that are too big to be representable using any supported >> integer type, and the same is true of pointer differences. > >Indeed. For example in x86 16-bit real mode (think MS-DOS) it may >well be that a pointer is 32-bit (because it has to contain a >segment and an offset) but ptrdiff_t may well be 16-bit, and the >compiler may limit eg. arrays to 64 kilobytes (minus 1 byte) so >that they will fit inside a segment. > >A difference between pointers will only give a valid (16-bit) >result when they point to the same array (which would be within >the same segment). Else you get garbage (if the two pointers are >pointing to different segments). I was discussing from the POV of a proper OS, not some half baked monitor program from the 70s. However if you can't work out how to get a valid diff from the above then clearly your maths skills need some work.