4gl variable quirk
Posted in 2009
Poster found that in Informix 4GL, local variables in a function can contain leftover data from a previously called function's variables that occupied the same memory, and asked whether 4GL should auto-initialise variables to NULL. Replies explained this is expected behaviour of the C-compiler (C4GL) version, since generated C code doesn't guarantee initialisation; the RDS (p-code) version and Aubit4GL do initialise variables to null/zero. Suggested fixes: use RDS/Aubit4GL, explicitly initialise variables, or run Aubit4GL's 4GL Lint (or tools like Purify) to find uninitialised variables. No product change was promised.
Auto-generated by DrWatson from the posts below — may be imperfect; read the full thread.
Topics: Stored Procedures & SPL, Connectivity: ESQL/C, 4GL & Embedded SQL
We've recently encountered an interesting quirk involving Informix 4gl function variables. When a 4gl program exits a function, memory assignments for any variables defined within the function are released. However, the variable contents remain in memory. When the 4gl enters another function new variables are assigned the same memory space. If formats match, the new variables have the same contents as previous variables which occupied the same memory space. Example 4gl.... database <dbname> main call loop2() call loop1() call loop2() end main function loop1() define loop1_var char(10) let loop1_var = 'test' end function function loop2() define loop2_var char(5) display "|",loop2_var, "|" end function results.... | | |test | I've already made the following request to our Informix Lab Advocate. Request: We would like to have 4gl variables automatically initialized to null when they are defined and the memory is allocated. This could potentially be implemented as new permanent behavior or as a compiler option. I'm posting the subject here to gauge the views of other 4gl users. Dave Griffen
This is a known "feature" of the c compiler version of 4gl... Informix4GL RDS (and Aubit4GL - C compiler version) automatically intializes the variables to null (or 0 depending on the datatype IIRC)... FWIW - this is/was one of the major porting issues between RDS and C-compiler versions. You write the program in RDS - then when rolled out using C-Compiler version suddenly things would stop working because they were not explicitly initialized. So - use RDS (or Aubit4GL) and you should be ok :-) 2009/8/18 DAVE GRIFFEN <dgriffen@finishline.com> > We've recently encountered an interesting quirk involving Informix 4gl > function variables. When a 4gl program exits a function, memory assignments > for any variables defined within the function are released. However, the > variable contents remain in memory. When the 4gl enters another function > new > variables are assigned the same memory space. If formats match, the new > variables have the same contents as previous variables which occupied the > same > memory space. Example 4gl.... > > database <dbname> > main > > call loop2() > > call loop1() > > call loop2() > end main > function loop1() > > define loop1_var char(10) > > let loop1_var = 'test' > end function > function loop2() > > define loop2_var char(5) > > display "|",loop2_var, "|" > end function > > results.... > | | > |test | > > I've already made the following request to our Informix Lab Advocate. > > Request: We would like to have 4gl variables automatically initialized to > null > when they are defined and the memory is allocated. This could potentially > be > implemented as new permanent behavior or as a compiler option. > > I'm posting the subject here to gauge the views of other 4gl users. > > Dave Griffen > > > > ******************************************************************************* > Forum Note: Use "Reply" to post a response in the discussion forum. > > --00148531b92c112c4704716f0b31
C4GL code is compiled down to C code under the hood and C does not guarantee the contents of variables that are not explicitly initialized. What you really need is a 4GL Lint tool to go through your code and let you know where you have such uninitialized variables so you can fix them. Fortunately, Aubit4GL comes with such a 4GL Lint tool. You can download Aubit4GL and even if you continue to compile with standard IBM Informix C4GL, you can still use the Lint. Art Art S. Kagel Oninit (www.oninit.com) IIUG Board of Directors (art@iiug.org) Disclaimer: Please keep in mind that my own opinions are my own opinions and do not reflect on my employer, Oninit, the IIUG, nor any other organization with which I am associated either explicitly or implicitly. Neither do those opinions reflect those of other individuals affiliated with any entity with which I am affiliated nor those of the entities themselves. On Tue, Aug 18, 2009 at 2:02 PM, DAVE GRIFFEN <dgriffen@finishline.com>wrote: > We've recently encountered an interesting quirk involving Informix 4gl > function variables. When a 4gl program exits a function, memory assignments > for any variables defined within the function are released. However, the > variable contents remain in memory. When the 4gl enters another function > new > variables are assigned the same memory space. If formats match, the new > variables have the same contents as previous variables which occupied the > same > memory space. Example 4gl.... > > database <dbname> > main > > call loop2() > > call loop1() > > call loop2() > end main > function loop1() > > define loop1_var char(10) > > let loop1_var = 'test' > end function > function loop2() > > define loop2_var char(5) > > display "|",loop2_var, "|" > end function > > results.... > | | > |test | > > I've already made the following request to our Informix Lab Advocate. > > Request: We would like to have 4gl variables automatically initialized to > null > when they are defined and the memory is allocated. This could potentially > be > implemented as new permanent behavior or as a compiler option. > > I'm posting the subject here to gauge the views of other 4gl users. > > Dave Griffen > > > > ******************************************************************************* > Forum Note: Use "Reply" to post a response in the discussion forum. > > --000e0cdfca04eba30104716f89d9
>>This is a known "feature" of the c compiler version of 4gl... Does anyone find this "feature" useful?
DAVE GRIFFEN wrote: >>> This is a known "feature" of the c compiler version of 4gl... >>> > > Does anyone find this "feature" useful? > > It's got nothing to do with the fact that it's 4gl and all to do with the fact that the code compile to 'c'. If you don't initialize your declared variables, you only have yourself to blame. Read Art's answer for a fuller explanation. Then sack your programmers! Malc
I used to use Rational's Purify to detect this kind of thing (and lots of other stuff too...) > To: ids@iiug.org > From: iiug@perrior.net > Subject: Re: 4gl variable quirk [16716] > Date: Tue, 18 Aug 2009 16:50:49 -0400 > > DAVE GRIFFEN wrote: > >>> This is a known "feature" of the c compiler version of 4gl... > >>> > > > > Does anyone find this "feature" useful? > > > > > It's got nothing to do with the fact that it's 4gl and all to do with > the fact that the code compile to 'c'. > If you don't initialize your declared variables, you only have yourself > to blame. > Read Art's answer for a fuller explanation. Then sack your programmers! > > Malc > > > ******************************************************************************* > Forum Note: Use "Reply" to post a response in the discussion forum. > _________________________________________________________________ Windows Live Messenger: Celebrate 10 amazing years with free winks and emoticons. http://clk.atdmt.com/UKM/go/157562755/direct/01/