[Freeciv-Dev] Re: Profiling Civserver again
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
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
- [Freeciv-Dev] Re: map_adjust_x (was: Profiling Civserver again), (continued)
- [Freeciv-Dev] Re: Profiling Civserver again, Reinier Post, 2001/08/02
- [Freeciv-Dev] map_adjust_x (was: Profiling Civserver again), Mike Kaufman, 2001/08/02
- [Freeciv-Dev] Re: map_adjust_x (was: Profiling Civserver again), Reinier Post, 2001/08/02
- [Freeciv-Dev] Re: Profiling Civserver again, Vasco Alexandre Da Silva Costa, 2001/08/01
- [Freeciv-Dev] Re: Profiling Civserver again, Ross W. Wetmore, 2001/08/01
- [Freeciv-Dev] Re: Profiling Civserver again, Robert Brady, 2001/08/01
- [Freeciv-Dev] Re: Profiling Civserver again, Vasco Alexandre Da Silva Costa, 2001/08/01
- [Freeciv-Dev] Re: Profiling Civserver again, Trent Piepho, 2001/08/01
- [Freeciv-Dev] Re: Profiling Civserver again,
Vasco Alexandre Da Silva Costa <=
- [Freeciv-Dev] Re: Profiling Civserver again, Trent Piepho, 2001/08/02
- [Freeciv-Dev] Re: Profiling Civserver again, Greg Wooledge, 2001/08/02
- [Freeciv-Dev] Re: Profiling Civserver again, Jules Bean, 2001/08/02
- [Freeciv-Dev] Re: Profiling Civserver again, Gaute B Strokkenes, 2001/08/06
- [Freeciv-Dev] Re: Profiling Civserver again, Gaute B Strokkenes, 2001/08/02
- [Freeciv-Dev] Re: Profiling Civserver again, Paul Zastoupil, 2001/08/02
- [Freeciv-Dev] Re: Profiling Civserver again, Lino Mastrodomenico, 2001/08/03
- [Freeciv-Dev] Re: Profiling Civserver again, Gaute B Strokkenes, 2001/08/03
- [Freeciv-Dev] Re: Profiling Civserver again, Gaute B Strokkenes, 2001/08/04
|
|