Function typedefs have any use?
Kevin P. Fleming
kpfleming@starnetworks.us
Mon Feb 7 03:03:00 GMT 2005
Gabriel Dos Reis wrote:
> I guess "pointless" is in the eye of beholder. I've used that ability
> quite a lot in some projects, where a large number of functions
> sharing the same prototype has to be declared.
But you still had to repeat the prototypes when defining the functions,
so it did not provide as much benefit as it could... the declarations
automatically change when you modify the typedef, but the function
definitions don't.
> Care to make a concrete proposal? There is no point in complaining
> if you can't improve over the situation...
Sure, how would I go about doing that? Obviously it would be a GCC
extension only, but I think it could be useful.
Something as simple as:
typedef char *f_t(char, char, void *);
f_t f;
f(p1, p2, p3)
{
}
This would define function f, taking three parameters (p1, p2 and p3),
and the return value type and all parameter types would be as specified
in the forward declaration of the function. If there is no forward
declaration, this syntax would generate a compile error. If the number
of parameter does not match the number parameters specified in the
forward declaration, this would also generate a compile error. All the
normally available attributes and modifiers would be available as well
(static, const, pure, etc.).
More information about the Gcc-help
mailing list