[fpc-pascal] using functions from units & main programme

Bart bartjunk64 at gmail.com
Fri Nov 18 18:15:23 CET 2011


{file: jim.pas}
unit jim;

{$ifdef fpc}
  {$mode objfpc}{h+}
{$endif}

interface

function fna: string;
function fnb: string;

implementation

function fna: string;
begin
  fna := 'jim';
end;

function fnb: string;
begin
  fnb := fna;
end;

end.


{file: prog.pas}
Program Prog;
{$ifdef fpc}
  {$mode objfpc}{h+}
{$endif}

uses jim;

function fna: string;
begin
  fna := 'Prog';
end;

begin
  writeln('fna = ',fna);
  writeln('jim.fna = ,'jim.fna);
end.

Compiled with both TurboPascal 6.0 and fpc 2.4.4. the output in both
cases is "Prog".
To get "Jim" in the main program file (prog.pas) I have to use jim.fna
explicitely:

Turbo Pascal  Version 6.0  Copyright (c) 1983,90 Borland International
fna = Prog
jim.fna = jim

Free Pascal Compiler version 2.4.4 [2011/04/23] for i386
Copyright (c) 1993-2010 by Florian Klaempfl
Target OS: Win32 for i386
Compiling prog.pas
Linking prog.exe
16 lines compiled, 0.8 sec , 26912 bytes code, 1624 bytes data

F:\TP6>prog
fna = Prog
jim.fna = jim

Bart



More information about the fpc-pascal mailing list