7.9.1.2. GEL Function Parameters

See also:

GEL Functions: Alphabetical List

You can pass arguments to a GEL function by defining Parameters in the GEL function definition. Unlike C function Parameters, the Parameters type is not defined; only the Parameters name is required. The Parameters type is determined automatically from the argument passed. GEL Parameters can be any of the following:

  • An actual or simulated target symbol value, if a target symbol is passed
  • A numerical constant, if any expression or constant value is passed
  • A string constant, if a string constant is passed

The argument that is passed at execution time determines the values the Parameters takes on.

The following is a GEL function definition:

Initialize(a, filename, b)
{
targVar = b;
a = 0; /* a symbol must be passed for Parameters ‘a’ */
GEL_Load(filename); /* a string constant must be passed for filename */
return b*b;
}

The following is an example of a correct call to the previous GEL function:

Initialize(targetSymbol, “c:\myfile.out”, 23 * 5 + 1.22);

When the function is executed, Parameters a is determined to be the symbol targetSymbol, Parameters filename is determined to be the string constant “c:myfile.out”, and Parameters b is calculated to be the constant value 116.22. These values are used in the function in place of the Parameters.

If a symbol was not passed for Parameters a, you will get a run-time error when executing the second statement, a = 0. For example, if you passed a constant value of 20, the second statement is equivalent to 20 = 0, which is not a valid assignment statement.

Even if a valid symbol is passed for the first Parameters, you must ensure that the code that defines the symbol is loaded into the Code Composer Studio debugger before you execute the GEL function. If the symbol is not defined, a run-time error will occur when executing the second statement, a = 0. Similarly, the code that contains the declaration for targVar must also be loaded before executing the function. Otherwise, a run-time error will occur when executing the first statement, targVar = b.

If the symbol targetSymbol is defined, the above call to this function assigns 0 to the target symbol.

GEL Parameters can be numerical values or strings, such as 1, 3.1415, 0x100, c:\filename, etc. For numerical Parameters, GEL allows you to pass any valid C expression. The expression is evaluated before it is passed to the GEL function. If the final value contains a period or the exponent sign (for example 1.2 or 1.34e4), it is assumed to be of type real; otherwise, it is assumed to be an integer.

You can call the initialize GEL function with either of the following formats:

  • Initialize(targetSymbol, “c:\mydir\myfile.out”, 10);
  • Initialize(targetSymbol, “c:\filename.out”, 1.2);

In the first call, Parameters b is assumed to be an integer value. The second call determines the input to be of type real. If the target variable targVar is of type int, then Parameters b is truncated during the assignment to targVar.

When you define a GEL function using Parameters symbols, passing it an argument is optional. This is because the Parameters values are initialized to 0 for numerical values and to a null string otherwise. If no Parameters are passed, the function assumes the default values for the Parameters. This means you can also call the previous function as follows:

  • Initialize();
  • Initialize(targSymbol, “c:\myfile.out”);

The first call assigns targVar to 0. However, an error is encountered when it tries to execute the statement GEL_Load(filename). With no argument passed for the file name, the statement is equivalent to GEL_Load(“”) and results in an Invalid File Name error. You also get an error on the statement a = 0. The second call to the Initialize function passes only two arguments to the function. The third is automatically assigned to 0.

GEL is very loosely defined, which provides the flexibility to make GEL function calls simple if you use default values. It also provides you the opportunity to pass more Parameters if you wish. You can see this with GEL built-in functions, such as GEL_TextOut that can take up to six arguments. For an advanced application, you may want to use all the Parameters to provide great control over the output. You can also call this function using only one Parameters, as follows:

GEL_TextOut(“Hello World!”);