Vanguard Software
Forecasting & Planning Solutions
Home Products Solutions Services Customers Partners Company
 
Applying science to business management

contents.gifindex.gifprev1.gifnext1.gif

Function Pointers

After declaring a function, you call it using a statement that includes the function name followed by input arguments enclosed in parentheses. For example, assume you have defined the function Square as

Square(x):=x*x

You call the function Square in another statement by using the expression

Square(3)

But what if you want to make the function you call a dynamic value that is chosen at runtime?  One way to do this is to use a function pointer. That is, you can create a variable, set its value to a pointer that represents the function Square, and call Square indirectly. For example,

var f=Square;
f(3);

The value of the variable f is a pointer to Square. Therefore, the expression f(3) is the same as Square(3).

Note that you can only create pointers to functions that accept input arguments. If you had defined Square as

Square:=3*3

the statement f=Square; will assign the number 9 to f instead of assigning a pointer to the function Square.

If you want to create a pointer to a function that does not have input arguments, you will first need to modify the function so that it includes a dummy argument. For example,

Square(none):=3*3

var f=Square;
f();

  Demand Planning  |  Financial Forecasting
Forecasting Software  |  Strategic Planning Software  |  Decision Tree Software
Decision Support Software  |  Expert System Software  |  Online Surveys

Contact Us  |  Terms of Use  |  Privacy Policy  |  Site Map
Vanguard Software
© 2011 Vanguard Software Corporation
Print this page   Email this page to a friend