Re: I don't understand typedef example



On 23 Mrz., 01:17, pete <pfil...@xxxxxxxxxxxxxx> wrote:
André Hänsel wrote:
Thanks for all your answers. They make it clear. So I understand that
all the author wanted to say is that there is no syntax in C to use a
typedef'd function type to define (or even declare) a function of that
type.

Since the only use of such a typedef is to make a type "pointer to
such a function" I probably will stick to the "typedef int
*pointer_to_such_function(int,int)" syntax in my own code.

Did you understand the part of the answers
which explained about the author being wrong?

You *can* use a typedef to declare a function.

Actually I don't think the author is wrong but he expresses the facts
in a very unfortunate way. I think by the sentence "As a word of
warning, typedef can only be used to declare the type of return value
from a function, not the overall type of the function." he means
something like "The typedef'd 'type name' cannot be used to define a
function of this type, it can only be used to define a function
returning a pointer to a funtion of this type."
This is what you meant by "using a typedef to declare a function",
isn't it? Or is there really a way to define a function of this very
type?
.



Relevant Pages

  • Re: If you could change the C or C++ or Java syntax, what would you like different?
    ... in the way it was done (i.e., refer to the declaration of a new type as "strong typedef"), you ... when you declare a new type the main motivation is to benefit from the need to comply with the ... There would be little desire to create a pointer type which is ... we want implicit conversion rules between ...
    (comp.lang.c)
  • Re: Simple question on Pointers
    ... It is undefined to use plain old scalar delete on ... hacks) You can't declare a charEVER. ... As for the inability to declare a variable with that syntax, ... without having to introduce a typedef to insert the variable names before ...
    (microsoft.public.vc.language)
  • Re: I dont understand typedef example
    ... * Using typedef, declare 'func' to have type ... 'function taking two int arguments, ... declared ptr as a pointer object that can points to a function of the ...
    (comp.lang.c)
  • Re: I dont understand typedef example
    ... Since the only use of such a typedef is to make a type "pointer to ... You *can* use a typedef to declare a function. ... char string1[sizeof STRING1]; ... const unsigned char *p2 = s2; ...
    (comp.lang.c)
  • Re: I dont understand typedef example
    ... Using typedef, declare 'func' to have type ... 'function taking two int arguments, ...
    (comp.lang.c)