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: Tue, 10 Aug 2021 06:41:18 -0700
Organization: A noiseless patient Spider
Lines: 38
Message-ID: <86y299zabl.fsf@linuxsc.com>
References: <86im0h2fi1.fsf@linuxsc.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="8983d14e45a299e43fc74f5563f3d6b2"; logging-data="17376"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18guTLIX39YjmsYGygVfT6aNHbljNLyImo="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:nc8H4B4n3S3L7KTkWjd0VSsEmqo= sha1:6vi8hr1fzRPSHEtNVa5lROI0OJM=
Xref: csiph.com comp.lang.c++:80824
MrSpud_HG@_0b772d8ha3yjo0xb.edu writes:
> On Mon, 9 Aug 2021 12:16:46 -0400
> James Kuyper wrote:
>
>> On 8/9/21 4:19 AM, MrSpud_ifhov@nldls6_1kg3nl2qnwv.biz wrote:
[...]
>>> So long as mathematical operations can be done on the pointer
>>> types (which is a given or they'd be no use as pointers) then
>>> they are de facto integer types and that statement is wrong.
>>
>> Yes, but when these issues come into play, the relevant
>> mathematical operations cannot be done on pointer types.
>> The result of a pointer
>
> They can in *nix which is good enough for me.
A few comments...
One, in many cases C pointers are represented internally as what
are basically integers, but the C standard says pointer types are
distinct from integer types, and the rules for operations on
pointer types, in particular subtraction of pointer values, are
specifed in terms of pointers and arrays and not in terms of
integer values. The rules for pointer subtraction depend on the
range of the implementation-chosen type ptrdiff_t.
Two, the specific values used for things like ptrdiff_t are
determined by the particular C implementation being used, not the
operating system. The target OS may influence some choices made
by the implementation, but it is still the implementation's
choice whether to observe those influences.
Three, I can tell you from first-hand experience that problems
related to the range of ptrdiff_t can and do occur in ordinary C
code running on a 32-bit linux system, using gcc to compile.