typedef as return type

Hi all,
I was browsing through an SDK (Filemaker plugin SDK) and stumbled upon the following code:
#define FMX_PROCPTR(retType, name) typedef retType (*name)
In another header the macro was used as follows:
FMX_PROCPTR( errcode, ExtPluginType ) ( short functionId, const ExprEnv& env, const DataVect& parms, Data& result );
Substituting the macro with its definition I would say this translates as:
typedef errcode (*ExtPluginType) ( short functionId, const ExprEnv& env, const DataVect& parms, Data& result )
(Between the latter parantheses are several classes that are declared before this statement and the errcode type is defined in another header.)

I was wondering, is this a function and if so, what is the name of the function? Or is it a complicated type definition wich includes parameters? Or am I missing something here?
It's a function pointer. The macro only defines the name and the return type, the parameters are attached.
I don't think this is a function. It's a function pointer type.

It will let us define a pointer to any function that looks like this:
errcod SomeFunction(short, const ExprEnv&, const DataVect&, Data&)

Let's take a simpler example:
typedef double (*p_func)(double);
p_func is now a type that lets us define a pointer to a function that takes a double and returns a double. We can do some fun things now like:
double CalcSinCos(bool horizontal, double x)
    p_func swappedFunction;
    if (horizontal) swappedFunction= sin; 
    else            swappedFunction= cos;

    return swappedFunction(x);

In your example: ExtPluginType is now exactley like our p_func in the simple example above. It lets us define a pointer to a function.
Last edited on
Thanks a lot. That is exactly the answer I didn't know I was looking for :)
Topic archived. No new replies allowed.