Path: utzoo!attcan!uunet!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!wuarchive!udel!haven!mimsy!chris From: chris@mimsy.umd.edu (Chris Torek) Newsgroups: comp.lang.c Subject: Re: 10 commandments and the NULL pointer? Message-ID: <27541@mimsy.umd.edu> Date: 8 Nov 90 16:11:08 GMT References: <2390@krafla.rhi.hi.is> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 31 In article <2390@krafla.rhi.hi.is> einari@rhi.hi.is (Einar Indridason) writes: >However one question entered my mind: (a question that perhaps should >be in the FAQ list, and perhaps is there?) It is. >int do_something(int *par1, double *par2, char *par3) ... > x = do_something(NULL, NULL, NULL); > /* is ^^^^ ^^^^ ^^^^ this right or should I write: */ You have provided a prototype declaration (via a preceding prototype definition) in which all three parameters are covered by prototypes. They are therefore in assignment contexts and as a result, an integer constant zero or same-cast-to-void (NULL expands to one of these two) suffices, because the pointer context is supplied by the assignments. > 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?) */ Some people prefer the latter form even when prototypes are used, as it helps remind the reader what is going on. Still others prefer something like: /* special distinguished second parameter to DoSomething */ #define NOMATRIX ((double *)NULL) ... x = do_something(NOFOO, NOMATRIX, NOBAR); -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 405 2750) Domain: chris@cs.umd.edu Path: uunet!mimsy!chris