Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 ggr 10/10/85; site bentley.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxt!houxm!ihnp4!bentley!kwh From: kwh@bentley.UUCP (KW Heuer) Newsgroups: net.lang.c Subject: Re: To dereference or not dereference, that is the question Message-ID: <613@bentley.UUCP> Date: Thu, 6-Mar-86 17:55:50 EST Article-I.D.: bentley.613 Posted: Thu Mar 6 17:55:50 1986 Date-Received: Sun, 9-Mar-86 00:32:15 EST References: <196@aplvax.UUCP>, <44@umcp-cs.UUCP> Organization: AT&T Bell Laboratories, Liberty Corner Lines: 25 Keywords: type casts,function pointers In article <44@umcp-cs.UUCP> umcp-cs!chris (Chris Torek) writes: > int f(), (*p)(); > p = f; > p(1); > (*p)(2); > (**p)(3); > (****************p)(4); Although there is no excuse for "p(1)", the other three examples are in fact correct. Recall that there are only two things you can do with a function (not a pointer): call it (as in f()) or take its address (any other use of the name). Thus "p = f" takes the address of function f and stores it in pointer p. Now consider "(**p)(3)". "*p" is of type _function_, but it is not being called (since the next operator is "*" rather than "()"), so we have to take its address. This leaves us with (* pointer_to_function)(3) which is legal. Each time you add a "*" you convert a pointer into a function, but if you don't immediately call it, you are taking its address again. Similarly, you could write "(*exit)(0)". For these reasons I think the address operator should have been required, "p = &f"; as the language stands it is permitted but discouraged (lint warns).