Re: Funny function or ...
Posted in 1993
My guess without testing is that the compiler is having a problem with modular and local variables of the same name. Try giving the local variables a different name and see if your problem is solved. BTW: if you really mean the variables to be modular, there's no need to pass them to a function in the same module. ================ Dennis J. Pimple Informix CSE / Denver pp@q8.dk (Poul Pedersen) writes: >#****************************************************************************** ># thru.4gl Funny program, which by a function call, can change the ># contents of your variables without letting you know. ># ># I will like to receive a comment on what I am doing wrong. ># ># Regards from: ># ----------------------------------------------------------------- ># Databaseadministrator Poul Pedersen ># Kuwait Petroleum (Danmark) A/S ># Hummeltoftevej 49 Mail: pp@q8.dk ># 2830 Virum Voice: +45 45 98 45 94 ># Denmark Fax: +45 42 85 14 18 ># ----------------------------------------------------------------- ># ># ># >#****************************************************************************** ># This funny program compiled with c4gl thru.4gl -o thru.4ge ># gave me the output (look at the output after the function call): ># ># parameters to f_func before call ># p1 :J ># p2 :N ># rec.d :OX ># rec.e : 1 ># rec.f : 2 ># ># I f_func ># p1 :J ># p2 :N ># rec.d :OX ># rec.e : 1 ># rec.f : 2 ># ># parameters to f_func after call ># p1 :J ># p2 :N ># rec.d :1 ># rec.e : 1 ># rec.f : 2 ># ># r_kode:-16676 ># ># I think, that the function call changed the contents of my variables ! ># >#****************************************************************************** >#Machine: Pyramid miserver under osx 5.1a >#I4GL verion: >#INFORMIX-4GL Version 4.10.UC4 >#SE version: >#INFORMIX-SQL Version 5.00.UC2 >#****************************************************************************** >DEFINE > p1 char(1), > p2 char(1), > rec record > a char(2), > b integer, > c integer, > d char(2), > e smallint, > f smallint > end record >MAIN > DEFINE > r_kode smallint > > LET p1 = 'J' > LET p2 = 'N' > LET rec.a = 'AA' > LET rec.b = 9 > LET rec.c = 99 > LET rec.d = 'OX' > LET rec.e = 1 > LET rec.f = 2 > DISPLAY "parameters to f_func before call" > DISPLAY "p1 :", p1 > DISPLAY "p2 :", p2 > DISPLAY "rec.d :", rec.d > DISPLAY "rec.e :", rec.e > DISPLAY "rec.f :", rec.f > LET r_kode = f_func(p1,p2,rec.d thru rec.f) > DISPLAY "" > DISPLAY "parameters to f_func after call" > DISPLAY "p1 :", p1 > DISPLAY "p2 :", p2 > DISPLAY "rec.d :", rec.d > DISPLAY "rec.e :", rec.e > DISPLAY "rec.f :", rec.f > DISPLAY "" > DISPLAY "r_kode:", r_kode >END MAIN >function f_func(p1,p2,rec) > DEFINE > p1 char(1), > p2 char(1), > rec record > d char(2), > e smallint, > f smallint > end record > DISPLAY "" > DISPLAY "I f_func" > DISPLAY "p1 :", p1 > DISPLAY "p2 :", p2 > DISPLAY "rec.d :", rec.d > DISPLAY "rec.e :", rec.e > DISPLAY "rec.f :", rec.f > return 1 >end function