This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Function typedefs have any use?


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.).


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]