Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!ut-sally!atc From: atc@ut-sally.UUCP (Alvin T. Campbell III) Newsgroups: comp.lang.c Subject: help with declaration Message-ID: <8286@ut-sally.UUCP> Date: Wed, 17-Jun-87 16:30:14 EDT Article-I.D.: ut-sally.8286 Posted: Wed Jun 17 16:30:14 1987 Date-Received: Sun, 21-Jun-87 10:24:44 EDT Organization: U. Texas CS Dept., Austin, Texas Lines: 45 Keywords: function pointer I have a question for all you C wizards out there. I want to write a function which returns a pointer to another function. I checked Kernighan & Ritchie and Harbison & Steele, but found no solution. My specific application is that I am writing a program which uses menus. Each menu item has an associated function which should be called when that item is selected. I want to write a function which puts a menu on the screen, lets the user select an item, and then returns the appropriate function. I want to structure the code as follows: #define TRUE 1 main() { int (*func)(); while(TRUE) { func = getmenu(); (*func)(); } } So how do I declare getmenu() ? I am writing the code on a Silicon Graphics, Inc. IRIS 2400, whose flavor of UNIX is System V with Berkeley Enhancements. The vendor has a hotline for questions, so I called there first. I was referred to someone in their compiler group. He told me to just declare getmenu() as an integer function, since it would work in this case. I am a purist, so I found this suggestion disgusting. By the way, please don't suggest that I restructure my code to avoid the problem. I know there are many ways to do this, and in fact I have done so already. I am just curious to see how to do it right. Thanks for the help. A. T. Campbell University of Texas at Austin Computer Graphics Lab atc@sally.CS.UTEXAS.EDU