Dear All
After 2 years of using gpc I thought I'd better update to a newer release, so I have installed gcc-2.95.3 and gpc-20010512.
It appears than an old bug has resurfaced. A global variable declared in a module is not initialised properly.
The following code does NOT print out the string 'OK':
-------main.h------------ var s: string(40); external;
procedure print_globals; external; -------------------------
-------main.p------------ program main(input,output);
#include "main.h"
begin s:='OK'; print_globals; end. -------------------------
-------lib.p------------- module lib(input,output);
#include "main.h"
var s:string(40);
procedure print_globals; begin writeln(s); end;
end. -------------------------
Compile with 'gpc -o main main.p lib.p'
If you move the declaration of string 's' from lib.p to main.p it works.
This was fixed about 2 years ago (by Peter I think) but it seems to have gotten un-fixed.
The initialisation code for the Main program, when the variable 's' is defined in the module in lib.p, is not correct. If you do:
# gpc -c lib.p # gpc -S main.p # vi main.s and add "movl $40,S" before .L6: in init_pascal_main_program, then # as -V -Qy -o main.o main.s GNU assembler version 2.10.91 (i386-redhat-linux) using BFD version 2.10.91.0.2 # gpc -o main main.o lib.o # ./main OK
you get the expected result.
Hope there is enough information to fix the problem.
Many thanks
Ian -- Ian Thurlbeck http://www.stams.strath.ac.uk/ Statistics and Modelling Science, University of Strathclyde Livingstone Tower, 26 Richmond Street, Glasgow, UK, G1 1XH Tel: +44 (0)141 548 3667 Fax: +44 (0)141 552 2079 °ïS