[fpc-pascal] Converting old pascal written for Pascal/MT+ compiler

Michael Van Canneyt michael at freepascal.org
Tue Apr 4 09:05:31 CEST 2023



On Tue, 4 Apr 2023, Jacob Kroon via fpc-pascal wrote:

> Hi Charlie, everyone,
>
> On 3/28/23 11:33, Karoly Balogh wrote:
>
> [cut]
>
>> 
>> If you want to export a variable without name mangling, you must declare a
>> public name for it, something like:
>> 
>> var
>>    foobar: integer; public name '_myfoobar';
>> 
>> Then reference it as:
>> 
>> var
>>    foobar: integer; external name '_myfoobar';
>> 
>
> [cut]
>
> Thanks for the tip above.
>
> I was able to write a couple of perl-scripts that are able to convert my old 
> Pascal sources to something that fpc can parse. Amongst other things, the 
> scripts inject the "public name"/"external name" annotations so that the 
> program can link.
>
> But I suspect I have a new problem: With the old Pascal/MT+ compiler it would 
> appear that local variables declared in functions/procedures have a life-time 
> that spans the whole program, like a "static" declared variable in C. With 
> fpc, it looks like locally declared variables are automatic, put on the 
> stack(?), and so they go out of existence once out of scope ?
>
> The program depends on this feature in the old compiler. I did some googling 
> and found that putting local variables in a "const" section instead of "var" 
> would make them have a "whole-program" lifetime, but then I need to provide 
> them with an initial value.
>
> Do I have any other option besides changing from "var" to "const" everywhere, 
> and provide initial values in all declarations ?

Make them actually global variables.

procedure X;

Var
  y : integer;

begin
// Use y
end;

becomes

var x__y : integer;

procedure x;

begin
   // use x__y 
end;

I did this operation manually for some programs that I had to update.
Maybe perl can help.

Michael.




Michael.


More information about the fpc-pascal mailing list