Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2004-08

Where is the error?

9 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Alan Mead

I am trying to compile a Delphi matrix package using fpc 1.9.4 and I don't know if I misunderstand FPC's overloading or if there is an FPC problem. The code is located here:

http://www.fssc.demon.co.uk/Delphi/delphi.htm#TMatrix

Lines 84-85 define a transpose method:

84 function transpose : TMatrix; {overload;}
85 function transpose (m : TMatrix) : TMatrix; {overload;}

(I commented out the overload keyword.. doesn't seem to matter.). I don't see any forward declaration of 'transpose':

misc code]$ grep -i transpose mat.pas

                   function  transpose : TMatrix; overload;
                   function  transpose (m : TMatrix) : TMatrix;

overload;
{ Transpose matrix 'Self', Self is thus destroyed and replaced }
{ Usage: A.transpose
}
function TMatrix.Transpose : TMatrix;
{ move data from transpose to Self }
{ Transpose the matrix 'm' into Self
}
{ Usage: T.transpose (A); Tranposes A and puts result into T }
{ Will also accept T.transpose (T)
}
function TMatrix.Transpose (m : TMatrix) : TMatrix; raise EMatrixSizeError.Create ('Destination matrix has incorrect dimensions for transpose');
{ If the user is trying to transpose itself.... }

    tmp.Transpose (st);
    Self.Transpose (ns);

This is the output when I try to compile:

 misc code]$ fpc -gl -S2 -Cr -Co mat.pas
Free Pascal Compiler version 1.9.4 [2004/05/30] for i386
Copyright (c) 1993-2004 by Florian Klaempfl
Target OS: Linux for i386
Compiling mat.pas
mat.pas(85,41) Error: Duplicate identifier "M"
mat.pas(85,30) Error: Function is already declared Public/Forward
"TMatrix.transpose:TMatrix"
mat.pas(87,38) Error: Duplicate identifier "M"
mat.pas(89,38) Error: Duplicate identifier "M"
mat.pas(90,38) Error: Duplicate identifier "M"
mat.pas(91,30) Error: Function is already declared Public/Forward
"TMatrix.mult(Extended):TMatrix"
mat.pas(93,38) Error: Duplicate identifier "M"
mat.pas(103,40) Error: Duplicate identifier "M"
mat.pas(117,73) Error: Duplicate identifier "c"
mat.pas(118,48) Error: Duplicate identifier "r"
mat.pas(118,73) Error: Duplicate identifier "c"
mat.pas(119,59) Error: Duplicate identifier "r"
mat.pas(127,1) Fatal: There were 12 errors compiling module, stopping

Any ideas on getting fpc to compile this? I'm confused by the reference to 'm'?

-Alan

Reply by email

Michalis Kamburelis
to Alan Mead

When you compile using -S2 parameter you are compiling in objfpc mode. This mode is not exactly compatible with Delphi. In this particular case, the problem is that in objfpc mode method parameters can't have the same name as the object properties and fields (that's what "Duplicate identifier ..." errors mean). That's often very nice safety-check, however it makes many Delphi code invalid in objfpc mode.

Solution is to compile in delphi mode:
fpc -Mdelphi mat.pas
works OK.

Alan Mead wrote 69 lines
I am trying to compile a Delphi matrix package using fpc 1.9.4 and I don't know if I misunderstand FPC's overloading or if there is an FPC problem. The code is located here: http://www.fssc.demon.co.uk/Delphi/delphi.htm#TMatrix Lines 84-85 define a transpose method: 84 function transpose : TMatrix; {overload;} 85 function transpose (m : TMatrix) : TMatrix; {overload;} (I commented out the overload keyword.. doesn't seem to matter.). I don't see any forward declaration of 'transpose': misc code]$ grep -i transpose mat.pas function transpose : TMatrix; overload; function transpose (m : TMatrix) : TMatrix; overload; { Transpose matrix 'Self', Self is thus destroyed and replaced } { Usage: A.transpose } function TMatrix.Transpose : TMatrix; { move data from transpose to Self } { Transpose the matrix 'm' into Self } { Usage: T.transpose (A); Tranposes A and puts result into T } { Will also accept T.transpose (T) } function TMatrix.Transpose (m : TMatrix) : TMatrix; raise EMatrixSizeError.Create ('Destination matrix has incorrect dimensions for transpose'); { If the user is trying to transpose itself.... } tmp.Transpose (st); Self.Transpose (ns); This is the output when I try to compile: misc code]$ fpc -gl -S2 -Cr -Co mat.pas Free Pascal Compiler version 1.9.4 [2004/05/30] for i386 Copyright (c) 1993-2004 by Florian Klaempfl Target OS: Linux for i386 Compiling mat.pas mat.pas(85,41) Error: Duplicate identifier "M" mat.pas(85,30) Error: Function is already declared Public/Forward "TMatrix.transpose:TMatrix" mat.pas(87,38) Error: Duplicate identifier "M" mat.pas(89,38) Error: Duplicate identifier "M" mat.pas(90,38) Error: Duplicate identifier "M" mat.pas(91,30) Error: Function is already declared Public/Forward "TMatrix.mult(Extended):TMatrix" mat.pas(93,38) Error: Duplicate identifier "M" mat.pas(103,40) Error: Duplicate identifier "M" mat.pas(117,73) Error: Duplicate identifier "c" mat.pas(118,48) Error: Duplicate identifier "r" mat.pas(118,73) Error: Duplicate identifier "c" mat.pas(119,59) Error: Duplicate identifier "r" mat.pas(127,1) Fatal: There were 12 errors compiling module, stopping Any ideas on getting fpc to compile this? I'm confused by the reference to 'm'? -Alan _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Marc Santhoff
to Michalis Kamburelis: When you compile using -S2 parameter you are compiling in objfpc mode. This mode is not…
Show quoted text 10 lines
When you compile using -S2 parameter you are compiling in objfpc mode. This mode is not exactly compatible with Delphi. In this particular case, the problem is that in objfpc mode method parameters can't have the same name as the object properties and fields (that's what "Duplicate identifier ..." errors mean). That's often very nice safety-check, however it makes many Delphi code invalid in objfpc mode. Solution is to compile in delphi mode: fpc -Mdelphi mat.pas works OK.

This leads me to the question:

Is it "legal" to link together objects compiled in different modes? (I haven't tried if it is possible at all ...)

For example Alan would compile his matrix stuff in delphi mode and link to other object files compiled in objpas mode?

TIA,
Marc

Reply by email

Unknown author
to Marc Santhoff
Marc Santhoff wrote 19 lines
Am Di, den 31.08.2004 schrieb Michalis Kamburelis um 22:25: > When you compile using -S2 parameter you are compiling in objfpc mode. > This mode is not exactly compatible with Delphi. In this particular > case, the problem is that in objfpc mode method parameters can't have > the same name as the object properties and fields (that's what > "Duplicate identifier ..." errors mean). That's often very nice > safety-check, however it makes many Delphi code invalid in objfpc mode. > > Solution is to compile in delphi mode: > fpc -Mdelphi mat.pas > works OK. This leads me to the question: Is it "legal" to link together objects compiled in different modes? (I haven't tried if it is possible at all ...) For example Alan would compile his matrix stuff in delphi mode and link to other object files compiled in objpas mode?

This is not a problem. The generated code is the same, independent of the mode. The mode only affects the parsing, and how identifiers are interpreted.

Michael.

Reply by email

Olle Raab
to Unknown author

04-09-01 09.29, skrev följande:

Show quoted text 27 lines
On Wed, 1 Sep 2004, Marc Santhoff wrote: > Am Di, den 31.08.2004 schrieb Michalis Kamburelis um 22:25: >> When you compile using -S2 parameter you are compiling in objfpc mode. >> This mode is not exactly compatible with Delphi. In this particular >> case, the problem is that in objfpc mode method parameters can't have >> the same name as the object properties and fields (that's what >> "Duplicate identifier ..." errors mean). That's often very nice >> safety-check, however it makes many Delphi code invalid in objfpc mode. >> >> Solution is to compile in delphi mode: >> fpc -Mdelphi mat.pas >> works OK. > > This leads me to the question: > > Is it "legal" to link together objects compiled in different modes? (I > haven't tried if it is possible at all ...) > > For example Alan would compile his matrix stuff in delphi mode and link > to other object files compiled in objpas mode? This is not a problem. The generated code is the same, independent of the mode. The mode only affects the parsing, and how identifiers are interpreted.

But can Delphi classes be used if you are in e g TP mode ?

Reply by email

Marc Santhoff
to Unknown author: This is not a problem. The generated code is the same, independent of the mode. The mode…

Am Mi, den 01.09.2004 schrieb um 09:29:
[...]

Show quoted text 11 lines
> This leads me to the question: > > Is it "legal" to link together objects compiled in different modes? (I > haven't tried if it is possible at all ...) > > For example Alan would compile his matrix stuff in delphi mode and link > to other object files compiled in objpas mode? This is not a problem. The generated code is the same, independent of the mode. The mode only affects the parsing, and how identifiers are interpreted.

Ah, I see.

Thank you very much,
Marc

Reply by email

Unknown author
to Olle Raab: 04-09-01 09.29, skrev följande: But can Delphi classes be used if you are in e g TP…
Olle Raab wrote 31 lines
04-09-01 09.29, skrev f�ljande: > > > On Wed, 1 Sep 2004, Marc Santhoff wrote: > >> Am Di, den 31.08.2004 schrieb Michalis Kamburelis um 22:25: >>> When you compile using -S2 parameter you are compiling in objfpc mode. >>> This mode is not exactly compatible with Delphi. In this particular >>> case, the problem is that in objfpc mode method parameters can't have >>> the same name as the object properties and fields (that's what >>> "Duplicate identifier ..." errors mean). That's often very nice >>> safety-check, however it makes many Delphi code invalid in objfpc mode. >>> >>> Solution is to compile in delphi mode: >>> fpc -Mdelphi mat.pas >>> works OK. >> >> This leads me to the question: >> >> Is it "legal" to link together objects compiled in different modes? (I >> haven't tried if it is possible at all ...) >> >> For example Alan would compile his matrix stuff in delphi mode and link >> to other object files compiled in objpas mode? > > This is not a problem. The generated code is the same, independent of the > mode. The mode only affects the parsing, and how identifiers are > interpreted. But can Delphi classes be used if you are in e g TP mode ?

No. You need objfpc or delphi mode for that.

Michael.

Reply by email

Olle Raab
to Unknown author

04-09-01 13.40, skrev följande:

Show quoted text 5 lines
On Wed, 1 Sep 2004, Olle Raab wrote: > But can Delphi classes be used if you are in e g TP mode ? No. You need objfpc or delphi mode for that.

Then I suggest to add this to the documentation about the language modes.

The doc says that unit ObjPas is loaded, but nothing about which type of classes which can be uses.

Olle

Reply by email