Topic: Invalid pointer comparisons (was Propo


Author: clamage@Eng.Sun.COM (Steve Clamage)
Date: 16 Mar 1995 16:24:37 GMT
Raw View
In article brd@giga.bga.com, jamshid@ses.com (Jamshid Afshar) writes:
>THIS ARTICLES IS CROSSPOSTED TO comp.std.c.
>
>>I don't understand what you mean.  There is absolutely no checking in C or
>>C++ on pointer ranges.  You can always compare the value of a pointer (not
>>necessarily the value of what it _points_ to).
>>
>>eg: void* something;
>> void* somethingelse;
>> if (something != somethingelse) exit(1);
>
>I believe you are wrong.  ... [ example deleted ]
>
>This isn't terribly far-fetched.  I believe CenterLine's ObjectCenter
>debugger checks whether a pointer points into freed memory and gives
>an error message, even when the program just compares that pointer
>value against NULL.
>
>Can someone confirm that ANSI/ISO C allows implementations like this?

C allows you to compare any two pointers for equality providing each
pointer points to some object or function or is a null pointer, and
the pointers have been cast to a common type.

The value of an uninitialized pointer or a pointer that has been
free'd is "indeterminate". The results of accessing a pointer
with an indeterminate value are undefined. That is, a machine can
trap on reading the value of an indeterminate pointer, and the
CenterLine implementation you describe is also allowed.

---
Steve Clamage, stephen.clamage@eng.sun.com