On 23/07/2005, at 6:12 PM, Paul Schlie wrote:

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?

Consider an implementation which does garbage collection and compaction. In such an implementation, it might be quite inconvenient to have to maintain a consistent ordering for all pointers.

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?

Although the C language doesn't guarantee the availability of such support, there is nothing that prevents an implementation from saying that it supports it, and in fact GCC does say that it supports it, through the use of a construct like

((intptr_t) a) < ((intptr_t) b)

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to