Function parameters as host variables
You can use host variables as parameters to functions. You must precede the name of the host variable with the parameter keyword to declare it as a function parameter.
For example, the following figure shows a code fragment
with a Kernighan and Ritchie-style prototype declaration that expects
three parameters, two of which are host variables.
You can also declare parameter host variables with the
dollar sign ($) notation. For example, the following figure shows
the function header in Using EXEC SQL to declare host
variables as parameters to a Kernighan and Ritchie-Style function
declaration,
with the dollar sign ($) notation.
You can declare parameters in an ANSI-style prototype
function declaration as host variables as well. You can also put all
parameters to a prototype function declaration inside the EXEC SQL
declare section, even if some of the parameters cannot be used as
host variables. The following figure shows that the function pointer f can
be included in the EXEC SQL declare section, even though it is not
a valid host-variable type and cannot be used as a host variable.
The functionality that allows inclusion of function parameters
inside of the EXEC SQL declare section is in compliance with the requirement
that any valid C declaration syntax must be allowed inside the EXEC
SQL declare sections to use common header files for C and source
files. For more information about how to use common header files between
C and source
files, see ids_esqlc_0091.html#ids_esqlc_0091.
Important: If you want to define host
variables that are ANSI-style parameters, you must use the EXEC SQL
BEGIN DECLARE SECTION and the EXEC SQL END DECLARE SECTION syntax.
You cannot use the $BEGIN DECLARE and $END DECLARE syntax. This restriction
is because SQL statements that begin with the dollar sign ($) notion
must end with a semicolon (;). However, ANSI syntax requires that
each parameter in a parameter list does not end with a semicolon terminator,
but with a comma (,) delimiter.
The following limitations apply to using host variables
as function parameters:
- You cannot declare a parameter variable inside a block of C code.
- You cannot use the parameter keyword in declarations of host variables that are not part of a function header. If you do, you receive unpredictable results.