Hi,
FPC allows to use two different units with the same name:
uses foo in 'unit1.pas', bar in 'sub/unit1.pas';Which might fail with linking errors.
Is this a feature or a bug?
Mattias

Mailing lists / fpc-pascal / 2018-02
8 messages · 3 people ·
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
Hi,
FPC allows to use two different units with the same name:
uses foo in 'unit1.pas', bar in 'sub/unit1.pas';Which might fail with linking errors.
Is this a feature or a bug?
Mattias
A feature.
First of all, normally it won't work either way, because you must use "unit foo;" and "unit bar;" in the files. A quick test confirms this:
home:~/source/testsub> fpc a.pp
unit1.pas(1,9) Error: Illegal unit name: foo (expecting FOO)
unit1.pas(7,1) Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation abortedWhere
a.pp:
-----
uses foo in 'unit1.pas', bar in 'sub/unit1.pas';
begin
dofoo;
dobar;
end.Unit1.pp:
---------
unit foo;
interface
procedure dofoo;
implementation
procedure dofoo;
begin
writeln('foo');
end;
end.sub/unit1.pp:
-------------
unit bar;
interface
procedure dobar;
implementation
procedure dobar;
begin
writeln('bar');
end;
end.But if you tell the compiler to ignore the unit filenames (-Un) then you get
home:~/source/testsub> fpc -Un a.pp
home:~/source/testsub> ./a
foo
bar
And then it works perfectly.
All assembler is prefixed using the declared
unit name:
.file "unit1.pas"
# Begin asmlist al_procedures
.section .text.n_foo_$$_dofoo
etc.
Michael.
[...] First of all, normally it won't work either way, because you must use "unit foo;" and "unit bar;" in the files.
No, I can use normal units. This works here:
---test1.pas---
uses foo in 'unit1.pas', unit1, bar in 'sub/unit1.pas';
Begin
i:=3; // from unit1.pas
foo.i:=foo.i+1; // from unit1.pas
bar.j:=27; // from sub/unit1.pas
writeln(foo.i,' ',unit1.i,' ',bar.j);
end.
---
---unit1.pas---
unit unit1;
interface
uses foo in 'sub/unit1.pas'; // unit1 uses another unit1
var i: integer;
implementation
end.
---
---sub/unit1.pas---
unit unit1;
interface
var j: integer;
implementation
end.
---Mattias
Strange. I get the error I showed if I try that.
Michael.
both of you are using the same mode? delphi or whatever? neither set of sample code shows a specific mode to use...
It works here with both -Mdelphi and -Mobjfpc
Free Pascal Compiler version 3.0.4
Compiler date : 2017/08/05
Compiler CPU target: x86_64
Mattias
And it works with
Free Pascal Compiler version 3.1.1
Compiler date : 2018/01/15
Compiler CPU target: x86_64
Mattias
A feature. First of all, normally it won't work either way, because you must use "unit…
This does not fit: Unit1.pp and unit1.pas.
Mattias