Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!zaphod.mps.ohio-state.edu!unix.cis.pitt.edu!dsinc!cdin-1!ki4pv!cdis-1!tanner From: tanner@cdis-1.compu.com (Dr. T. Andrews) Newsgroups: comp.lang.c Subject: Re: Pointers to functions Message-ID: <1TA00P3@cdis-1.compu.com> Date: 17 May 91 13:16:17 GMT References: <1512@caslon.cs.arizona.edu> Organization: CompuData, Inc. (DeLand) Lines: 45 X-Phone: +1 904 736 0866 X-Snail: 1409 E New York Ave; DeLand, FLA 32724. ) [ ``new'' function call syntax via pointer derives from c++ usage ] I don't think your explanation (function-call syntax derives from c++) is quite sufficient. I think that ANSI just made things consistant. Given int (*pf)(); int f(); int i, j; enum { ci=0x45 }; You can reasonably say pf = f; /* pf now points to function f */ because the bare ``f'' has the type ``pointer to function''. I can also say i = ci; /* i now has value 0x45 */ i = 0x45; /* same here. The types of ``pf'' and ``f'' are compatible. So are the types of ``i'' and ``ci'' (because in expressions, enums are ints), and the types of ``i'' and ``0x45''. The trick, in both cases, is that I have constants being assigned to variables. Both ``ci'' and ``f'' are constant values. Now, I can also say: i = f(); /* call func at f, stash value in i */ Why should I not declare that ``f'' is really a function pointer, and that such things are used by following them with parens? After all, we've just seen (through assignment to ``pf'') that we can interpret the value of ``f'' as a function pointer. If ``f'' is a function pointer, and so is ``pf'', then why should we not treat them similarly? In particular, why should we not also say: i = pf(); /* call func at pf, stash value in i */ We do not use different syntax for i = 1; and j = i; do we? As a sop to history, I note that some compilers accepted this argument before ANSI; it was ``prior art'' which has simply been formalized. Some compilers required no distinction between the form of call via the pointer ``pf'' and the name ``f''. Some did want the syntax ``(*pf)()''. -- uflorida!ki4pv!cdis-1!tanner {uunet dsinc}!cdin-1!cdis-1!tanner