Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rochester!crowl From: crowl@rochester.arpa (Lawrence Crowl) Newsgroups: comp.lang.c Subject: Re: help with declaration Message-ID: <364@sol.ARPA> Date: Thu, 18-Jun-87 08:59:11 EDT Article-I.D.: sol.364 Posted: Thu Jun 18 08:59:11 1987 Date-Received: Sun, 21-Jun-87 11:52:02 EDT References: <8286@ut-sally.UUCP> <7001@alice.UUCP> Reply-To: crowl@rochester.UUCP (Lawrence Crowl) Organization: U of Rochester, CS Dept, Rochester, NY Lines: 42 Keywords: function pointer In article <7001@alice.UUCP> ark@alice.UUCP writes: >The problem: how to declare a function that returns a function pointer: > >..., so we should say > > extern int (*getfunc())(); > >All clear? This is not clear. Let me propose a method for clearly coding complex declarations. I make use of the typedef facility. So, for the example above I will write: typedef int func_int() ; typedef func_int *ptr_func_int ; typedef ptr_func_int func_ptr_func_int() ; extern func_ptr_func_int getfunc ; So what does this method buy me? Well, it gives me a way to declare other complex types without consulting K&R and a couple of C wizards just to make sure the syntax is correct. For instance, how about a pointer to a function returning a pointer to an integer? typedef int *ptr_int ; typedef ptr_int func_ptr_int() ; typedef func_ptr_int *ptr_func_ptr_int ; extern ptr_func_ptr_int variable ; What have I lost? Well I have to type more. However, the typedefs need only be done once, so the true comparison is between: extern int (*getfunc())() ; and extern func_ptr_func_int getfunc ; I prefer the latter. -- Lawrence Crowl 716-275-5766 University of Rochester crowl@rochester.arpa Computer Science Department ...!{allegra,decvax,seismo}!rochester!crowl Rochester, New York, 14627