Re: Strange C constructs

Dave Thompson <david.thompson1@worldnet.att.net>
2 Mar 2004 11:07:35 -0500

          From comp.compilers

Related articles
Strange C constructs vbdis@aol.com (2004-02-26)
Re: Strange C constructs derek@NOSPAMknosof.co.uk (Derek M Jones) (2004-02-26)
Re: Strange C constructs iddw@hotmail.com (2004-02-27)
Re: Strange C constructs jeremy@jdyallop.freeserve.co.uk (Jeremy Yallop) (2004-02-27)
Re: Strange C constructs alexc@std.com (Alex Colvin) (2004-02-27)
Re: Strange C constructs derek@NOSPAMknosof.co.uk (Derek M Jones) (2004-03-02)
Re: Strange C constructs david.thompson1@worldnet.att.net (Dave Thompson) (2004-03-02)
Re: Strange C constructs vbdis@aol.com (2004-03-02)
Re: Strange C constructs viz@pisem.net (Victor Zverovich) (2004-03-02)
Re: Strange C constructs RLake@oxfam.org.pe (2004-03-06)
Re: Strange C constructs nmm1@cus.cam.ac.uk (2004-03-11)
| List of all articles for this month |
From: Dave Thompson <david.thompson1@worldnet.att.net>
Newsgroups: comp.compilers
Date: 2 Mar 2004 11:07:35 -0500
Organization: AT&T Worldnet
References: 04-02-147
Keywords: C, standards
Posted-Date: 02 Mar 2004 11:07:35 EST

On 26 Feb 2004 01:08:58 -0500, vbdis@aol.com (VBDis) wrote:
<snip>
> Another question may be easier to answer:
>
> typedef int (procname)(int arg);
>
> According to K&R only /pointers/ to procedure-types can be constructed. Does
> there exist newer specs which allow to typedef procedures themselves?


Assuming you mean K&R1? Since at least C89 = K&R2:


You can have a typedef for a function (of blah args returning x) type,
and you can use it to *declare* functions:
    procname somefunc; /* defined elsewhere */
    procname otherfunc; /* ditto */


You can also use it to declare a function parameter, since any
function parameter declared as a function is "rewritten" as pointer to
function, in the same way a parameter declared as array of T is
rewritten as pointer to T.


A function *definition* cannot use such a typedef; the grammar would
allow it, but it is prohibited by constraint 6.9.1p2 in C99, unchanged
from C90 except for numbering:


The identifier declared in a function definition (which is the name of
the function) shall have a function type, as specified by the
declarator portion of the function definition.137) where the footnote
explains in part: 137) The intent is that the type category in a
function definition cannot be inherited from a typedef: <etc.>


- David.Thompson1 at worldnet.att.net


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.