jeff@isi-vaxa.arpa (Jeffery A. Cavallaro) (11/28/85)
After all the talk about null object pointers on machines with non-zero null addresses, how would you portably define a null routine pointer?: Assume that the routine returns a short, - The following don't seem to work: #define NULLROUTINE ((short *()) 0) #define NULLROUTINE ((short *) 0()) And: #define NULLROUTINE ((short *0)()) or #define NULLROUTINE ((short)(*0)()) If all of the above make no sense...Then what? Jeff
gwyn@BRL.ARPA (VLD/VMB) (11/29/85)
((short (*)()) 0)
alexis@reed.UUCP (Alexis Dimitriadis) (12/02/85)
> After all the talk about null object pointers on machines with non-zero > null addresses, how would you portably define a null routine pointer?: Remember cdecl?? It says: ----------- % cdecl cast NULL into pointer to function returning short (short (*)())NULL ----------- so: #define NULLROUTINE ((short (*)()) 0 ) will do fine. Remember, NULL _is_ 0, even on machines where (byte pattern) zero is a valid address!! Alexis Dimitriadis -- _______________________________________________ Any opinions expressed above have been grown organically and contain no preservatives or artificial sweeteners. alexis @ reed {decvax,ihnp4,ucbcad,uw-beaver}!tektronix!reed.UUCP
bilbo.niket@locus.ucla.edu (Niket K. Patwardhan) (12/02/85)
Don't believe me 100%... things have changed since I learned my C. Try this (short (*)) 0 Doug Gwyn, Jim Cottrell, Ron Natalie .... do you want to confirm this?
bilbo.niket@locus.ucla.edu (Niket K. Patwardhan) (12/02/85)
I forgot a pair of parenthesis. (short (*())) 0
keesan@bbncc5.UUCP (Morris M. Keesan) (12/03/85)
The request was for a way to specify a null pointer to a function returning short. Doug Gwyn correctly responded with ((short (*)()) 0). Note that the form of the type specification is copied directly from section 8.7 of the C Reference Manual in K&R (page 200), and therefore very safe. For real readability, I as usual suggest the typedef method: typedef short FS(); /* FS = Function returning Short */ typedef FS *PFS; /* PFS = Pointer to Function returning Short */ #define NULLROUTINE ((PFS)0) /* Isn't this much clearer? */ -- Morris M. Keesan keesan@bbn-unix.ARPA {decvax,ihnp4,etc.}!bbncca!keesan
jsdy@hadron.UUCP (Joseph S. D. Yao) (12/03/85)
In article <218@brl-tgr.ARPA> bilbo.niket@locus.ucla.edu (Niket K. Patwardhan) writes: >I forgot a pair of parenthesis. >(short (*())) 0 Good: you added a pair of parentheses. Bad: one fell short. If I assigned this value to func, then called it, I would have to say: (*func)() The type that this returns is short. (Short int, more formally.) Therefore, I'd have to declare func: short int (*func)() and cast this (short int (*)()) 0. Doug already said this, but without explanation. -- Joe Yao hadron!jsdy@seismo.{CSS.GOV,ARPA,UUCP}
kenny@uiucdcsb.CS.UIUC.EDU (12/03/85)
/* Written 7:08 pm Nov 27, 1985 by jeff@isi-vaxa.arpa in uiucdcsb:net.lang.c */ /* ---------- "NULL ROUTINE POINTERS" ---------- */ After all the talk about null object pointers on machines with non-zero null addresses, how would you portably define a null routine pointer?: Assume that the routine returns a short, - The following don't seem to work: #define NULLROUTINE ((short *()) 0) #define NULLROUTINE ((short *) 0()) And: #define NULLROUTINE ((short *0)()) or #define NULLROUTINE ((short)(*0)()) If all of the above make no sense...Then what? Jeff /* End of text from uiucdcsb:net.lang.c */ To make a cast, write a (fully-parenthesized) declaration of one item of the desired type, and then take out the name. So, if you want a pointer to a function returning short, you might say short (*pfs) (); To cast 0 to this type, it's (short (*) ()) 0; so #define NULL_FUNCTION ((short (*) ()) 0) Kevin kenny@Uiuc.ARPA kenny@Uiuc.CSNET {ihnp4, pur-ee, convex}!uiucdcs!kenny No opinions are expressed here, so no disclaimer is needed.