Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!mit-eddie!ll-xn!ames!amdahl!oliveb!sun!guy From: guy@sun.uucp (Guy Harris) Newsgroups: comp.lang.c Subject: Re: how do I initialize a function pointer to be NULL ? Message-ID: <27742@sun.uucp> Date: Fri, 11-Sep-87 04:28:59 EDT Article-I.D.: sun.27742 Posted: Fri Sep 11 04:28:59 1987 Date-Received: Sat, 12-Sep-87 16:32:55 EDT References: <197@tiger.Princeton.EDU> Organization: Sun Microsystems, Inc. - Mtn View, CA Lines: 22 Keywords: NULLFUNC > If p is declared as : > struct x > { int (*p)(); }; > Now I want to initialize a variable y which is a structure x. > struct x y = { NULLFUNC }; > The question is what should I put into the #define NULLFUNC .... ? > (I am using Microsoft C 4.0). Thanks for your help. Unless Microsoft C 4.0 is badly broken, "#define NULLFUNC 0" should suffice; the compiler knows enough to coerce the "0" to a pointer of the appropriate type, and should do so in this context if it claims to implement C. NULL should also suffice, if it is defined as 0 or (sigh) 0L. If you want to pass a null pointer of the same type as the member of "x" to a function, and there is no prototype for that function in scope, you have to use a cast, as the compiler *doesn't* know enough to coerce "0" to a pointer of the appropriate type in that context. In that case, the properly-cast pointer is "(int (*)())0". -- Guy Harris {ihnp4, decvax, seismo, decwrl, ...}!sun!guy guy@sun.com (or guy@sun.arpa)