Path: utzoo!attcan!uunet!mcsun!tuvie!vmars!hp From: hp@vmars.tuwien.ac.at (Peter Holzer) Newsgroups: comp.lang.c Subject: Re: 10 commandments and the NULL pointer? Message-ID: <1959@tuvie> Date: 8 Nov 90 13:05:44 GMT References: <2390@krafla.rhi.hi.is> Sender: plank@tuvie Lines: 48 einari@rhi.hi.is (Einar Indridason) writes: >#include >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 ); > /* which form should I use? (that is, should I cast the NULL value */ > /* to int pointer, double pointer, char pointer?) */ >} >----------------------------------------- If you are using ANSI C, then the above form is allright, because the compiler knows from the prototype above the types of the pointers and inserts the casts by itself. If you (or someone else) want to port your program to an old compiler (and many of them are still in use) and change the declaration of do_something to: int do_something (par1, par2, par3) int * par1; double * par2; char * par3; { /* ... */ } you will need the casts because the compiler does not check (much less convert) any arguments. -- | _ | Peter J. Holzer | Think of it | | |_|_) | Technical University Vienna | as evolution | | | | | Dept. for Real-Time Systems | in action! | | __/ | hp@vmars.tuwien.ac.at | Tony Rand |