Xref: utzoo comp.lang.c++:13507 comp.std.c:4844 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!spool.mu.edu!munnari.oz.au!metro!extro!dpg From: dpg@extro.ucc.su.OZ.AU (D P Gilbert) Newsgroups: comp.lang.c++,comp.std.c Subject: Re: Pointers to functions Message-ID: Date: 17 May 91 04:18:18 GMT References: <1512@caslon.cs.arizona.edu> <4253@inews.intel.com> Sender: news@metro.ucc.su.OZ.AU Organization: Sydney University Computing Service, Sydney, NSW, Australia Lines: 40 Nntp-Posting-Host: extro.ucc.su.oz.au bhoughto@pima.intel.com (Blair P. Houghton) writes: >In article <1512@caslon.cs.arizona.edu> dave@cs.arizona.edu (Dave Schaumann) writes: >>You have found one of the weirdnesses of ANSI-C. When you have a pointer >>to a function, you (normally) invoke the function by saying >> (*funptr)() >>However, ANSI, in it's infinite wisdom, decided that you should be able to >>say >> funptr() >>in the same context, with similar results. >It's not weird at all. It's rather consistent. The actual >syntax is > () >where the expression must evaluate to a function pointer. >A similar thing is true of arrays, structs, and unions, where >the syntaxes are > [] > . > -> >The only thing remotely weird about it is that now `funptr' >and `*funptr' are the same thing, but that's why function >poiners are often singled out for different semantic >treatment in the standard (many things you can do with >a pointer to int are forbidden with a function pointer). As I reach for the shift button to put yet another set of left and right parentheses after a niladic function call I have begun to wonder how to relieve such tedium. Wouldn't it be nice just to write the function name without those parentheses (e.g. token.get instead of token.get() ). The syntax of C tells me why but could it be bent with a #pragma perhaps? Whenever I want the address of a function I use "&" so I can understand my code 18 months later. I know this amounts to heresy ... apologies in advance Doug Gilbert