Does anybody know if it is allowed to compare pointer using the
operators '<', '<=', '>' or '>='?
Yes, but with limitations. You're allowed to compare any two valid or
null pointers of compatible types[1] using == and !=. Using <, >, <= and
>=, though, there is the additional demand that they must point within
the same object (array, struct, union, etc.). If not, the behaviour is
undefined. That also means that you can't compare to a null pointer
(constant) using < or >.
Richard
[1] Or pointers to void, or pointers to qualified versions of compatible
types, or null pointer constants.
Does anybody know if it is allowed to compare pointer using the
operators '<', '<=', '>' or '>='?
If your textbook doesn't answer that question, get a better one. I
recommend K&R2 (Kernighan & Ritchie, _The C Programming Language_, 2nd
Edition).
--
Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
In article <ln3b9oowod.fsf @nuthaus.mib.or g>,
Keith Thompson <kst-u@mib.orgwrote:
>sebastien.fric ker@gmail.com writes:
>Does anybody know if it is allowed to compare pointer using the
>operators '<', '<=', '>' or '>='?
>
>If your textbook doesn't answer that question, get a better one. I
>recommend K&R2 (Kernighan & Ritchie, _The C Programming Language_, 2nd
>Edition).
Comment