View Single Post
Re: Storing an array of function calls, and their params.....
Old
  (#4)
Pierre-Marie Baty
Roi de France
 
Pierre-Marie Baty's Avatar
 
Status: Offline
Posts: 5,049
Join Date: Nov 2003
Location: 46°43'60N 0°43'0W 0.187A
Default Re: Storing an array of function calls, and their params..... - 16-05-2005

thinking in terms of memory occupation helps a lot. You have:
Code:
typedef struct
{
	int foo; // this is an integer, i.e. 4 bytes
 
	// this is a pointer, thus a long, i.e. 4 bytes too.
	int (*fooFunc) (int *param1, int *param2);
} my_func_t;
fooFunc is a pointer, which means, no matter how many trailing parameters you put on that line to the fooFunc function, its representation will be identical in every instance of the struct: 4 bytes, filled with the address of the function you will be calling.

With this:
Code:
callerFunc->fooFunc = MyCoolFunc(12, 13);

you are not storing the address of MyCoolFunc and its parameters, you are CALLING MyCoolFunc() with 12 and 13 as parameters, and storing... its return value.

That's not quite the same thing!



RACC home - Bots-United: beer, babies & bots (especially the latter)
"Learn to think by yourself, else others will do it for you."
  
Reply With Quote