Complete.Org: Mailing Lists: Archives: freeciv-dev: August 2001:
[Freeciv-Dev] Re: Profiling Civserver again
Home

[Freeciv-Dev] Re: Profiling Civserver again

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: Profiling Civserver again
From: Vasco Alexandre Da Silva Costa <vasc@xxxxxxxxxxxxxx>
Date: Thu, 2 Aug 2001 05:20:43 +0100 (WET DST)

On Wed, 1 Aug 2001, Trent Piepho wrote:

> On Thu, 2 Aug 2001, Vasco Alexandre Da Silva Costa wrote:
> > 
> > when this is much more compact:
> > 
> > if (!p)
> > if (p)
> 
> Are you SURE that is ok?  I seem to remember reading in the comp.lang.c FAQ
> that a NULL pointer is defined as a pointer to 0, but not necessarily the
> value 0.  They even gave some examples of systems where NULL!=0.

IIRC a NULL pointer always has the value 0. I know the prophets K&R use
the most verbose form but this quote is from The C Programming Language
2nd edition, page 102:

"Pointers and integers are not interchangeable. Zero is the sole
exception: the constant zero may be assigned to a pointer, and a pointer
may be compared with the constant zero. The symbolic constant NULL is
often used in place of zero as a mnemonic to indicate more clearly that
this is a special value for a pointer".

Of course this sentence is unclear. Do they mean you must do it like this
if you want to use 0?:

if (p==0)
if (p!=0)

In practice i have programmed on a MUD codebase that used p & !p and it
runs hapilly on these platforms:

Digital UNIX    - Alpha         - cc
Solaris         - Sparc         - gcc
HP UX           - PA-RISC       - c89
Irix            - MIPS          - cc
Windows         - x86           - MS VC++ 6.0

If that isn't portable i don't know what is. Its portable enough to me
anyway. You must cast NULL to the appropriate pointer type when passing it
has a function argument. I have stumbled into this once using varargs.

...Searching for the C FAQ on google....

Apparently the C FAQ says i'm right. Yupiee! :-)

http://www.eskimo.com/~scs/C-faq/q5.3.html

---
Vasco Alexandre da Silva Costa @ Instituto Superior Tecnico, Lisboa





[Prev in Thread] Current Thread [Next in Thread]