Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.sys.ibm.pc,comp.lang.c Subject: Re: Assigning to Pointers Message-ID: <6611@mimsy.UUCP> Date: Sun, 10-May-87 10:57:36 EDT Article-I.D.: mimsy.6611 Posted: Sun May 10 10:57:36 1987 Date-Received: Mon, 11-May-87 02:46:23 EDT References: <3537@vrdxhq.UUCP> <857@killer.UUCP> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 52 Xref: mnetor comp.sys.ibm.pc:3929 comp.lang.c:2130 In article <857@killer.UUCP> jfh@killer.UUCP (John Haugh) writes: >The parenthesis come in real handy at times, for example (small lesson in >C to follow :-) when you can't figure out how to declare a 'something' with >a weird shape. My weakness is pointers to functions - > int foo (); /* this is a function */ Right; > int *foo (); /* this is a function RETURNING a pointer */ right; and > int *(foo ()); /* pointer to first function */ wrong: this last is `function returning pointer to int'. >I won't even bother with POINTER to FUNCTION returning POINTER to FUNCTION >returning an integer (the return value of signal() is one of these). Actually, the return value from signal is not representable, as it is `pointer to function returning pointer to function returning pointer to function returning ...', with no final type. Instead, we all cheat and use `pointer to function returning int' (or, in some cases, `returning void'). The program `cdecl' is handy for this sort of thing. It has been posted several times, so your neighbor probably has a copy, and it is available via anonymous FTP from host mimsy.umd.edu on the ARPAnet. % cdecl declare foo as pointer to function returning pointer to \ function returning int int (*(*foo)())() (cdecl does not handle `\' continuation lines; this is purely a mailer-bug-avoidance device) explain int (*(*foo)())() declare foo as pointer to function returning pointer to \ function returning int You can create horrendous things that no one ever would use: declare a as array 5 of pointer to function returning pointer to \ pointer to function returning pointer to array 3 of pointer to char char *(*(**(*a[5])())())[3] Amaze your friends by getting types like this right the first time! -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690) Domain: chris@mimsy.umd.edu Path: seismo!mimsy!chris