Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sdd.hp.com!hplabs!hpl-opus!hpcc05!hpwrce!walterm From: walterm@hpwrce.HP.COM (Walter Murray) Newsgroups: comp.lang.c Subject: Re: Re: oops... (was Re: Pointers to functions) Message-ID: <580004@hpwrce.HP.COM> Date: 17 May 91 16:30:01 GMT References: Organization: HP's Western Response Center Lines: 51 steve@taumet.com (Stephen Clamage) writes: > aj3u@wilbury.cs.virginia.edu (Asim Jalis) writes: >>What is the difference between these two (pf is a pointer to a >>function, and hello is a function): >>pf = hello; >>and >>pf = &hello; > There is no difference. The oddity is this: A function designator > appearing in an expression context is replaced by the address of the > function, making a pointer-to-function. Attempts to take the address > of the function designator are ignored. So > hello > &hello > &&&&&&&&&&&&&&&&hello > are all equivalent. I would say that an attempt to take the address of a function designator is honored, but is unnecessary because it's a conversion that is done automatically anyway. And the third example has problems. First, && will be taken as a logical AND operator, resulting in a syntax error. We can correct that by writing: & & & & & & & & & & & & & & & &hello; But it seems to me this is still illegal. When & is applied to a function designator, the result is a pointer to a function and is not an lvalue. This pointer-to-function does not get converted back to a function designator. Applying the next & should cause a diagnostic, because the operand of & must be either a function designator or an lvalue, and &hello is neither. Relevant sections in the Standard are 3.2.2.1 and 3.3.3.2. > Similarly, when you dereference a pointer-to-function, you get a > function designator, which is replaced by pointer-to-function. > Consequently, > pf() > (*pf)() > (****************pf)() > are all equivalent. Right. Walter Murray ----------