This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Pointers in comparison expressions
- From: Paul Schlie <schlie at comcast dot net>
- To: Geoffrey Keating <geoffk at geoffk dot org>
- Cc: <mrc dot lrn at inwind dot it>,<gcc at gcc dot gnu dot org>
- Date: Sat, 23 Jul 2005 21:12:52 -0400
- Subject: Re: Pointers in comparison expressions
> Geoffrey Keating wrote:
>> Mirco Lorenzon wrote:
>>
>> .., are comparisons in the following program legal code?
>
> No.
>
>> ...
>> void *a, *b;
>> ...
>> if (a < b)
>
> Because 'a' and 'b' are not part of the same array,
> the behaviour is undefined.
Although I don't mean to contest the conclusion, I do find it curious that
as all pointer values referencing unique objects must be correspondingly
unique, it would follow that they will be correspondingly ordered with
respect to each other. Therefore although technically undefined, it seems
quite reasonable to expect an implementation to support ordered inequality
comparisons between arbitrary pointers to equivalent effective types?
As it would seem otherwise impossible for an implementation to support the
ability to write code which enables the relative comparison of generalized
memory pointers unless one were to explicitly declare a union of an array
of all potentially allocateable memory, and all explicitly and implicitly
declared objects; which doesn't seem reasonable?