Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!rutgers!mit-eddie!genrad!decvax!decwrl!sun!gorodish!guy From: guy@gorodish.UUCP Newsgroups: comp.lang.c Subject: Re: C pointer to a function Message-ID: <29213@sun.uucp> Date: Sun, 27-Sep-87 01:46:12 EDT Article-I.D.: sun.29213 Posted: Sun Sep 27 01:46:12 1987 Date-Received: Sun, 27-Sep-87 22:15:05 EDT References: <501@acf3.NYU.EDU> Sender: news@sun.uucp Distribution: na Lines: 26 Keywords: static pointer function > The question here concerns the scope of the pointer to > the function foo. > Specifically, why might the pointer be defined as static? Which "pointer to the function foo"? There are no pointers to functions anywhere in your example (nor are there any in Rochkind's example, either). The only things declared as static here are the function "foo" ( static char *foo(name) does NOT declare a function pointer, it declares a function that *returns* a pointer) and the variable "path". The reason why "path" is declared "static" was given by another poster; it cannot be automatic, because a pointer to it is returned by "foo", but when "foo" returns "path" will be discarded and the pointer to it will no longer be a pointer to a valid object. The reason why "foo" is declared "static" is that it is presumably not used by any code outside the module in which it is defined, and it is good programming practice not to export anything from a module unless it is to be used by code outside that module - in other words, declare everything with file scope "static" unless you can't do so. Guy Harris {ihnp4, decvax, seismo, decwrl, ...}!sun!guy guy@sun.com