Re: Function typedefs have any use?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Gabriel Dos Reis wrote:
"Kevin P. Fleming" <kpfleming@xxxxxxxxxxxxxxx> writes:

| Eljay Love-Jensen wrote:
| | > But the syntax of C doesn't have the language construct of "here's a
| > label (identifier), here's the type of that label, and here's it's
| > body".

<snip>

You mean like this:

      typedef int F(int);
      F f;      /* function "f" taking an int and returning an int. */

Well, I was wrong... it does not work. This specific example works, but only because the default return type for a function is "int".


If you try this with a typedef-ed function returning anything but int, you'll get errors from the compiler about incompatible definitions of the function.

So, that leaves me back at my original quandary: I can create a typedef of a function type, and I can use that typedef to declare function pointers to hold addresses of compatible functions, but I can't use the typedef to actually _declare_ those compatible functions (I have to write the prototype of the function to match the typedef, and if I don't do it correctly then any errors that the compiler finds will be at places where the function's address is assigned to a function pointer, not at the function definition itself). Bummer.

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux