O
ozbear
This is probably an obvious question.
I know that pointer comparisons are only defined if the two pointers
point somewhere "into" the storage allocated to the same object, or if
they are NULL, or one-past the end of the object as long as it isn't
dereferenced.
I use "object" in the standard 'C' sense.
Is there some special dispensation given to comparing two pointers
that are -each- one past the end of the object as opposed to
comparing a one-past-end pointer and an pointer expression derived
referencing the actual object. Given the following definitions:
char arr[100];
char *pend = &arr[99];
char *pa = pend+1;
char *pb = pend+1;
is the comparison pa == pb guaranteed to be meaningful or does it
invoke UB because -neither- pa nor pb point into arr.
In otherwords, from the standard's point of view, is there a
semantic difference between comparing pa and pb and comparing,
say, pa and &arr[99]+1 ?
Oz
I know that pointer comparisons are only defined if the two pointers
point somewhere "into" the storage allocated to the same object, or if
they are NULL, or one-past the end of the object as long as it isn't
dereferenced.
I use "object" in the standard 'C' sense.
Is there some special dispensation given to comparing two pointers
that are -each- one past the end of the object as opposed to
comparing a one-past-end pointer and an pointer expression derived
referencing the actual object. Given the following definitions:
char arr[100];
char *pend = &arr[99];
char *pa = pend+1;
char *pb = pend+1;
is the comparison pa == pb guaranteed to be meaningful or does it
invoke UB because -neither- pa nor pb point into arr.
In otherwords, from the standard's point of view, is there a
semantic difference between comparing pa and pb and comparing,
say, pa and &arr[99]+1 ?
Oz