471,071 Members | 975 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,071 software developers and data experts.

Comparing Pointer

Does anybody know if it is allowed to compare pointer using the
operators '<', '<=', '>' or '>='?
Oct 16 '06 #1
3 9461
se***************@gmail.com wrote:
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.
Oct 16 '06 #2
se***************@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).

--
Keith Thompson (The_Other_Keith) ks***@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.
Oct 16 '06 #3
In article <ln************@nuthaus.mib.org>,
Keith Thompson <ks***@mib.orgwrote:
>se***************@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).
In some prints of the book, the section on pointer comparisons
(A7.10) has an omission that is corrected in the errata, see
http://cm.bell-labs.com/cm/cs/cbook/2ediffs.html .
Oct 17 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by agent349 | last post: by
6 posts views Thread by Pierre McCann | last post: by
5 posts views Thread by ma740988 | last post: by
12 posts views Thread by barcaroller | last post: by
20 posts views Thread by Bill Pursell | last post: by
9 posts views Thread by subramanian100in | last post: by
25 posts views Thread by J Caesar | last post: by
7 posts views Thread by arnuld | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.