Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!rutgers!labrea!jade!ucbvax!hplabs!gatech!emory!platt From: platt@emory.UUCP Newsgroups: comp.lang.c Subject: Re: how do I initialize a function pointer to be NULL ? Message-ID: <2236@emory.uucp> Date: Fri, 11-Sep-87 22:11:22 EDT Article-I.D.: emory.2236 Posted: Fri Sep 11 22:11:22 1987 Date-Received: Sun, 13-Sep-87 07:54:20 EDT References: <197@tiger.Princeton.EDU> <27742@sun.uucp> Reply-To: platt@emory.UUCP (Dan Platt) Organization: Math & Computer Science, Emory University, Atlanta Lines: 34 Keywords: NULLFUNC In article <27742@sun.uucp> guy@sun.uucp (Guy Harris) writes: >> 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. >-- > Guy Harris > {ihnp4, decvax, seismo, decwrl, ...}!sun!guy > guy@sun.com (or guy@sun.arpa) Actually, depending on the model (the IBM machines have a segmented addressing scheme), NULL is defined as 0 if the memory is in small or medium models, and is defined as 0L in compact and large models. Since a module may need to be compiled several ways, rather than checking the compile flags in the preprocessor, it's easiest to just define it as #define NULLFUNC NULL, and including either or (either having NULL defined) before the other define. As far as the function is concerned, it doesn't care what kind of pointer is passed to it; it just passes an address. The declaration in the function where the routine is passed defines what the function is expected to do (whether the address is to be read/write, or called). Dan