function declarator strangeness
    Kirk 'UhOh' Johnson 
    tuna at athena.mit.edu
       
    Thu May 31 03:39:22 AEST 1990
    
    
  
the following bits of grammar are culled from appendix A of K&R (1st
ed.):
    function-declarator:                          /* page 204 */
        declarator ( parameter-list_opt )
    declarator:                                   /* page 194 */
        identifier
        ( declarator )
        * declarator
        declarator ( )
        declarator [ constant-expression_opt ]
so a function "foo" returning a pointer to a function returning an int
would be declared as:
    int (*foo())()
    {
      /* body of foo */
    }
imagine that i'd like "foo" to take one argument, arg, an integer.
given the bits of grammar shown above, i would expect use:
    int (*foo())(arg)
        int arg;
    {
      /* body of foo */
    }
unfortunately, both pcc and gcc choke upon such a declaration. but if
i rearrange things as
    int (*foo(arg))()
        int arg;
    {
      /* body of foo */
    }
both compilers generate code which seems to do the right thing,
despite the fact that this declaration of "foo" doesn't seem to match
the grammar shown in my copy of K&R (1st ed.).
anybody have any helpful comments? how should the function-declarator
grammar really read? if the problem is that K&R (1st ed.) is out of
date, is there a better reference that isn't?
although i will try to keep up with comp.lang.c to look for responses
to my questions, i'd appreciate it if responses could also be e-mailed
so i don't inadvertently miss them.
thanks in advance for any help
kirk
--
-------------------------------------------------------------------------------
kirk johnson                                                    `Eat blue dogs
tuna at masala.lcs.mit.edu                                          and dig life.'
    
    
More information about the Comp.lang.c
mailing list