Xref: utzoo comp.arch:4871 comp.lang.c:10187 Newsgroups: comp.arch,comp.lang.c Path: utzoo!henry From: henry@utzoo.uucp (Henry Spencer) Subject: Re: negative addresses Message-ID: <1988May19.172757.14990@utzoo.uucp> Organization: U of Toronto Zoology References: <2393@uvacs.CS.VIRGINIA.EDU> <21541@amdcad.AMD.COM> Date: Thu, 19 May 88 17:27:57 GMT > if (tp->t_tbuf.c_ptr) { >The C standards I've seen so far are pretty clear in stating that the >conditional is compared against zero. There doesn't seem to be leeway >to define pointer comparisons to be against some non-zero NULL value. Sigh. Not this again! If you *read* the fine print in the standards, you will find that this construct is 100.00000% equivalent to saying "if (tp->t_tbuf.c_ptr != NULL) {". In pointer contexts, which this is, the integer constant 0 stands for "whatever bit pattern is used for null pointers". When p is a pointer, "if (p)", "if (p != 0)" and "if (p != NULL)" are completely synonymous, by the definition of C. The problem that does come up is that compilers in general cannot tell whether a parameter in a function call is meant to be a pointer or not, and hence cannot supply the automatic conversion. There is also trouble with programs that explicitly convert pointers to integers and back. -- NASA is to spaceflight as | Henry Spencer @ U of Toronto Zoology the Post Office is to mail. | {ihnp4,decvax,uunet!mnetor}!utzoo!henry