# 7.9.1.2. GEL Function Parameters¶

You can pass arguments to a GEL function by defining parameters in the GEL function definition.

Differently than C language, the datatype of a parameter does not need to be defined and only its name is required. The datatype is determined automatically from the assigned value.

GEL Parameters can be any of the following:

• A debug symbol located on the actual target device (variable, function, etc.)
• 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 parameter takes on.

GEL parameters can be integers (decimal, hex), real (float), or strings, such as 1, 3.1415, 0x100, c:\workspace\filename, etc. For numerical parameters, GEL allows any valid C expression to be passed and 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.

GEL is very loosely defined, which provides the flexibility to make GEL function calls simple using default values. It also provides the opportunity to pass more parameters if desired. This can be seen in GEL built-in functions such as GEL_TextOut which can take up to six arguments. This can be called using only one parameter as follows:

GEL_TextOut("Hello World!");

In this particular function (useful for debugging and informative tasks during GEL execution) all the parameters can be used to provide greater control over the output.

___

Example:

The following is a GEL function definition:

Initialize(localSymbol, filename, value)
{
if (value > 10)
{
localSymbol = 0;
targetStatus = 10;
}
else
{
targetStatus = value;
}
return value*value;
}


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

Initialize(targetSymbol, "c:\\workspace\\myProject\\Debug\\myProject.dat", 2 * 5 + 1.22);

Just like in C, when the function is executed the parameter localSymbol is assigned to the symbol targetSymbol, the parameter filename is assigned to the string constant c:\users\user\workspace\myProject\Debug\myProject.out, and the parameter value is calculated and assumes the value 11.22.

The above call to this function tests the parameter value and makes a decision to either initialize the target symbols with init values or load data from the host.

In the example above, both targetStatus and targetSymbol must exist in the code loaded to the target device, otherwise a runtime error will happen when executing the assignment statements. Also, an invalid assignment to the parameter localSymbol would be a constant value (e.g. 20), since the assignment would be equivalent to 20 = 0, which is invalid.

Even if a valid symbol is passed for the parameter localSymbol, the code (with debug information) that defines the symbol must be loaded into the Code Composer Studio debugger before the function is executed. Otherwise, runtime errors will happen.

The initialize GEL function can be called with either of the following formats:

• Initialize(targetSymbol, "c:\\workspace\\myProject\\Debug\\myProject.dat", 10);
• Initialize(targetSymbol, "c:\\workspace\\myProject\\Debug\\myProject.dat", 1.2);

The calls assign an integer or a real value to the paramter value. If the target variable targetStatus is of type int, then the value is truncated during the assignment to targetStatus.

When a GEL function is defined using a symbol parameter, 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.

Thus the call to the function above can be done as follows:

• Initialize(targetSymbol, "c:\\workspace\\myProject\\Debug\\myProject.dat");

This call passes only two arguments to the function and the third is automatically assigned to 0.

• Initialize();

This is a valid call from the standpoint of GEL syntax and structure, but it will cause a runtime error given the statment GEL_MemoryLoad() has a null string. With no argument passed for the filename, the statement is equivalent to GEL_MemoryLoad(0, 0, 0x100, "") and results in an Invalid File Name error.

___