GLOBALS variables usage
This topic describes differences between I4GL and FGL regading global variables definitions and usage.
Mismatching global variable definitions
The c4gl C-code compiler of IBM® Informix® 4GL has a weakness that allows global variable declarations of
the same variable with different data types. Each different declaration found by the c4gl compiler
defines a distinct global variable, which can be used separately. This can actually be very
confusing (the same global variable name can, for example, reference a DATE value
in module A and an INTEGER value in module B).
IBM Informix 4GL RDS (fglpc / fglgo) does not allow multiple global variable declaration with different types. The fglgo runner raises error -1337 if this happens.
The next code example shows two .4gl modules defining the same global variable with different data types:
GLOBALS
DEFINE v INTEGER
END GLOBALS
...
MAIN
...
LET v = 123
...
END MAINGLOBALS
DEFINE v DATE
END GLOBALS
...
FUNCTION test()
...
LET v = TODAY
...
END FUNCTIONThe fglcomp tool compiles both modules separately without problem, but when linking with fgllink or fglrun -l, the linker raises error -1337.
You must review your code and use the same data type for all global variables having the same name.
Duplicated global variable definition
IBM Informix 4GL
produces a compilation error when same variable and type is defined in a GLOBALS / END
GLOBALS section in the current module, and the globals file included with a GLOBALS
"filename" instruction that defines the same variable.
GLOBALS
DEFINE var1 INTEGER
END GLOBALSGLOBALS "myglobals.4gl"
GLOBALS
DEFINE var1 INTEGER
END GLOBALS
MAIN
DISPLAY "var1 = ", var1
END MAINAs a general advice, avoid the use of global variables and use modules variables with
PUBLIC scope.