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

Jacob Kroon jacob.kroon at gmail.com
Tue Apr 4 08:16:39 CEST 2023

Hi Charlie, everyone,

On 3/28/23 11:33, Karoly Balogh wrote:


> 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';


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 ?


More information about the fpc-pascal mailing list