Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   definition of FUNCPTR (http://www.chiefdelphi.com/forums/showthread.php?t=70542)

shavol 12-12-2008 03:49

definition of FUNCPTR
 
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

Re: definition of FUNCPTR
 
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.

2roy999 12-12-2008 08:14

Re: definition of FUNCPTR
 
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

Re: definition of FUNCPTR
 
Code:

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

Re: definition of FUNCPTR
 
Soo... a function pointer holds the address of a function, it's arguments and return type?

jtdowney 27-12-2008 07:19

Re: definition of FUNCPTR
 
Quote:

Originally Posted by Bomberofdoom (Post 787424)
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

Re: definition of FUNCPTR
 
Quote:

Originally Posted by GabeRC1717 (Post 786963)
Code:

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.?


All times are GMT -5. The time now is 17:57.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi