Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site fortune.UUCP Path: utzoo!linus!philabs!seismo!harpo!eagle!mhuxl!ihnp4!fortune!mbr From: mbr@fortune.UUCP Newsgroups: net.unix Subject: Re: functions returning pionters to func - (nf) Message-ID: <1975@fortune.UUCP> Date: Wed, 14-Dec-83 19:24:49 EST Article-I.D.: fortune.1975 Posted: Wed Dec 14 19:24:49 1983 Date-Received: Fri, 16-Dec-83 03:02:41 EST Sender: notes@fortune.UUCP Organization: Fortune Systems, Redwood City, CA Lines: 73 #R:azure:-243000:fortune:26900002:000:1701 fortune!mbr Dec 14 12:34:00 1983 The easiest solution would be to use typedef: typedef int (*Fint)(); Fint getroutine(name, table) type declaration for name & table; { . . . } Your original solution of: int (*getroutine())(name, table) was close. If you don't want to use typedef, the correct declaration is: int (*getroutine(name, table))() I've tried this on 4.1, and cc is quite happy with it. Declarations of this complexity frequently get me muddled as well. I find the easiest way to think of it is to write the expression in which the type would appear, successively adding layers until I've reached a simple type (such as int), and then turn that into the declaration. For example: 1. Getroutine is a function, so the expression to call it would look like: getroutine(name, table) 2. The return value from getroutine is a pointer, so the expression to access its contents is: *getroutine(name, table) 3. The value it points at is the entry point of a function, so the expression to call the function is: (*getroutine(name, table))() 4. The value this function returns is an integer. The call to this function would use the returned integer for something integerlike: i = (*getroutine(name, table))(); or: if ( (*getroutine(name, table))() == 999) { /* do something */ } however, in a type declaration, you just need to state that what you've come up with is an integer and then define your function: int (*getroutine(name, table))() type declaration for name & table; { . . . } Mark Rosenthal {allegra,amd70,cbosgd,dsd,floyd,harpo,hpda,ihnp4, magic,megatest,nsc,oliveb,sri-unix,twg,varian,wdl1} !fortune!mbr