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.
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.
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 article.
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
typedef int (*FUNCPTR)(...);
You can have up to ten arguments, they have to be of the type “int”, see taskSpawn
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.
Can’t the int be typecast as a float, etc.?