[Function pointer] Translating these typedefs into one

M

mailforpr

typedef void(*int_arg)(int);
typedef int_arg(*pf)(int*,int*,int_arg);

I tried this:

typedef void(*)(int)(*ultra)(int*,int*,void(*)(int));

and got a syntax error.
 
R

Ron Natalie

typedef void(*int_arg)(int);
typedef int_arg(*pf)(int*,int*,int_arg);

I tried this:

typedef void(*)(int)(*ultra)(int*,int*,void(*)(int));

and got a syntax error.

No you got the return type wrong. You need to substitute
the rest of the function declaration where int_arg goes in
the original typedef:


typedef void (*(*ultra)(int*, int*, int_arg))(int);
 
K

Krishanu Debnath

typedef void(*int_arg)(int);
typedef int_arg(*pf)(int*,int*,int_arg);

I tried this:

typedef void(*)(int)(*ultra)(int*,int*,void(*)(int));

and got a syntax error.

Try this:

typedef void (*ultra(int*, int*, void(*)(int)))(int);

Krishanu
 
F

Frederick Gotham

(1) typedef void (*int_arg)(int);

This is a pointer to a function which takes an int and returns void.


(2) typedef int_arg (*pf)(int*,int*,int_arg);

This is a pointer to a function which takes three arguments:

int*
[ii] int*
[iii] void (*)(int)

And whose return type is:

void (*)(int);

Here's how we put them together. First of all, start off with the function
return type, which is ultimately the "fundamental type" of the entire
declaration:

void (*pf)(int);

From here, we turn it into a function by putting parentheses directly after
the name, and filling these parentheses with the function parameter types:

void ( *pf(int*,int*,void(*)(int)) )(int)

We now turn this into a pointer to what it already is by enclosing the name
in parentheses with an asterisk:

typedef void ( *(*pf)(int*,int*,void(*)(int)) )(int);

As follows:

typedef void (*int_arg)(int);

/* typedef int_arg (*pf)(int*,int*,int_arg); */

typedef void ( *(*pf)(int*,int*,void(*)(int)) )(int);

int main()
{
int_arg x;

pf p;

x = p(0,0,x);
}
 
R

Ron Natalie

Krishanu said:
Try this:

typedef void (*ultra(int*, int*, void(*)(int)))(int);

Krishanu
He could try it, but it wouldn't be right
*ultra( ... ) is a function returning pointer
not pointer to function. You need one more set of parens.
 
K

Krishanu Debnath

Ron said:
He could try it, but it wouldn't be right
*ultra( ... ) is a function returning pointer
not pointer to function. You need one more set of parens.

You are right of course. Thanks for the correction.

Krishanu
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top