Log in

View Full Version : definition of FUNCPTR


shavol
12-12-2008, 03:49
Hello, I am looking at the WPIlib code and have a question

in task.h line 39 I found the variable type 'FUNCPTR' and I didn't found the definition of it in the project, do you know what is the definition of it?

thanks a lot,
team 1937.

jtdowney
12-12-2008, 07:35
I am not certain which file it is defined in but what it is is a function pointer. It allows you to pass around a reference to functions of the same signature (same return type and parameter types). Function pointers are often used for callbacks where you will provide some function a pointer to a function they should call when some event happens. Wikipedia has a pretty good overview in their Function pointer (http://en.wikipedia.org/wiki/Function_pointer) article.

2roy999
12-12-2008, 08:14
Hello, I read what you wrote and I have a question

How can I know the return type of the function and the type of the function's arguments?

thank you,
Team 1937

GabeRC1717
24-12-2008, 15:46
typedef int (*FUNCPTR)(...);


You can have up to ten arguments, they have to be of the type "int", see taskSpawn

Bomberofdoom
27-12-2008, 06:06
Soo... a function pointer holds the address of a function, it's arguments and return type?

jtdowney
27-12-2008, 07:19
Soo... a function pointer holds the address of a function, it's arguments and return type?

Close, it is just the address of the function. You define the types for the parameters and return and the compiler will setup the function call correctly for you. It will also (if it can) double check that you are calling the function with the correct signature (signature being types of return and parameters) to prevent simple mistakes.

Dbruce1792
28-12-2008, 19:00
typedef int (*FUNCPTR)(...);


You can have up to ten arguments, they have to be of the type "int", see taskSpawn

Can't the int be typecast as a float, etc.?