Hi!
I've encountered some strange problem using GPC built from may on HPuix 11.00.
I declare public variables in module interface and then try to use them.
The problem is that while integer variables work perfectly all other kinds of variables (at least files and strings) don't work at all.
See the following small modules: ---------------mod1.pas------------------- module mod1 interface; export mod1 = all; Type mystr = string(7); Var my_str_var : mystr; my_int_var : integer; end.
module mod1 implementation; to begin do writeln ('Load mod1'); end.
---------------mod2.pas-------------------- module mod2 interface export mod2 = all; import mod1;
procedure sSet (str_arg : mystr); function sGet : mystr; procedure iSet (int_arg : integer); procedure iGet : integer;
end.
module mod2 implementation; import mod1
procedure sSet (str_arg : mystr); begin writeln ('mod2 sset str_arg:',str_arg,'.'); my_str_var := str_arg; writeln ('mod2 sset my_str_var:',my_str_var,'.'); end;
procedure iSet (int_arg : integer); begin writeln ('mod2 sset int_arg:',int_arg,'.'); my_int_var := int_arg; writeln ('mod2 sset my_int_var:',my_int_var,'.'); end;
function sGet : mystr; begin sGet := my_str_var; end;
function iGet : integer; begin iGet := my_int_var; end;
end. -----------------------my_main.pas------------------- program my_main (input,output); import mod1; import mod2;
Var another_str : mystr := '7654321'; another_int : integer := 361;
begin sSet ('0123456'); writeln ('1. my_main another_str:',another_str,'.'); another_str := sGet; writeln ('2. my_main another_str:',another_str,'.');
iSet (19); writeln ('1. my_main another_int:',another_int,'.'); another_int := iGet; writeln ('2. my_main another_int:',another_int,'.');
end. --------------------------------------------------------
Well, after I compile all 3 files and run the my_main what I get is: mod2 sset str_arg:0123456. mod2 sset my_str_var:. 1. my_main another_str:7654321. 2. my_main another_str:. mod2 iset int_arg:19. mod2 iset my_int_var:19. 1. my_main another_int:361. 2. my_main another_int:19.
After I copied the my_str_var definition to implementation as well I get the following result: mod2 sset str_arg:0123456. mod2 sset my_str_var:0123456. 1. my_main another_str:7654321. 2. my_main another_str:0123456. mod2 iset int_arg:19. mod2 iset my_int_var:19. 1. my_main another_int:361. 2. my_main another_int:19.
The strange is that after I moved my_str_var definition from mod1 implementation to my_main var definitions nothing changed.
May somebody explain me what is going on? Why integer is defined ok, but string has problem?
BTW as I stated earlier I have problem similar to string problem with File variables and any structures containing string fields.
Thank you in advance.
P.S. If the example doesn't compile - it is because of typos. I run GPC on system which is not connected to Internet, and the Internet computer doesn't have floppy.
P.P.S
I'd like to thank all of you who'd found out the problem with debuger.
Nick
Nick Ioffe wrote:
I declare public variables in module interface and then try to use them.
The problem is that while integer variables work perfectly all other kinds of variables (at least files and strings) don't work at all.
May somebody explain me what is going on? Why integer is defined ok, but string has problem?
It's a known problem:
: the capacity of strings declared in interfaces of modules is not : initialized (daj3.pas, sven14c.pas, nick1.pas)
Actually, it affects those types that require some automatic initialization which are schemata (including strings), files and objects.
It only happens with modules, not with units. I'll try to fix it when I get to it, but it's not trivial and will require some other cleaning up of the module mechanism ...
Frank