10 commandments and the NULL pointer?
Jan Christiaan van Winkel
jc at atcmp.nl
Fri Nov 9 00:09:50 AEST 1990
>From article <2390 at krafla.rhi.hi.is>, by einari at rhi.hi.is (Einar Indridason):
# int do_something(int *par1, double *par2, char *par3)
# {
# /* do something with those pointers/parameters */
# /* return some value to tell how well we did */
# }
#
#
# main()
# {
# .....
#
# x = do_something(NULL, NULL, NULL);
# /* is ^^^^ ^^^^ ^^^^ this right or should I write: */
#
# x = do_something( (int *)NULL, (double *)NULL, (char *)NULL );
# }
since you used prototypes, you can just as well use
x = do_something(0, 0, 0);
because the compiler knows the 0's are used in pointer context; it will
automagically cast the value to the right type. Read the FAQ for more
info on the NULL pointer, there's actually quite a lot to be told about
it.
JC
--
___ __ ____________________________________________________________________
|/ \ Jan Christiaan van Winkel Tel: +31 80 566880 jc at atcmp.nl
| AT Computing P.O. Box 1428 6501 BK Nijmegen The Netherlands
__/ \__/ ____________________________________________________________________
More information about the Comp.lang.c
mailing list