typedefing functions (Re: Is typedef char BUFFER[20] legal?)
Richard Kooijman
kooijman at duteca
Wed Feb 6 04:28:44 AEST 1991
henry at zoo.toronto.edu (Henry Spencer) writes:
>In article <ENAG.91Feb4192806 at holmenkollen.ifi.uio.no> enag at ifi.uio.no (Erik Naggum) writes:
>>you can say
>> typedef int f (int a, char *b);
>>and later say
>> f foo, bar, zot;
>>and
>> f *functab[3] = { foo, bar, zot, };
>Correct so far.
>>The functions would be declared
>> f foo
>> { ... }
>Nope, wrong. The function definition itself must contain an explicit
>function declarator; it cannot inherit its "functionness" from a typedef.
>See Constraints in 3.7.1.
But what is the reason? I think it severely limits the use of
typedef'ing functions, which could be otherwise very useful:
typedef void cntrlc_handler(void);
main()
{
cntrlc_handler c_handler;
signal(SIGINT, c_handler);
}
It is a shame to be forced to define c_handler again:
void c_handler(void)
{
...
}
Richard.
More information about the Comp.std.c
mailing list