Sign in Join

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

Mailing lists / fpc-devel / 2006-08

Problem with open arrays

7 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

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

Peter Popov

Hi
I have the following question: how are open array parameters currently implemented in FPC? The reason I am asking is that I am using DLL functions in C which rely on borland's syntax, that is,

void __cdecl SomeProc(const double *coords, const int high) (in C++ Builder)

is equivallet to either of the following Delphi constructs:

procedure SomeProc1(const coords: array of Double); cdecl;

or

PDouble = ^Double;
procedure SomeProc2(const coords: PDouble; const high: Integer); cdecl;

This allows seamless integration of Delphi functions with open arrays into C++ code and vice versa.

I know that fpc does not like open array functions declared with cdecl. So I am wondering wath is the internal representation and are such functions binary equivalent to the above C++ example?

For more information, see bug:
http://www.freepascal.org/mantis/view.php?id=6940

Peter Popov

Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

Reply by email

ik
to Peter Popov

Hi,

You should use
PDouble = ^Double;
procedure SomeProc2(const coords: PDouble; const high: Integer); cdecl;

The reason is simple, it's equal to C's code...

Open arrays are voodoo magic, specially for C\++ compilers..

Ido

Peter Popov wrote 36 lines
Hi I have the following question: how are open array parameters currently implemented in FPC? The reason I am asking is that I am using DLL functions in C which rely on borland's syntax, that is, void __cdecl SomeProc(const double *coords, const int high) (in C++ Builder) is equivallet to either of the following Delphi constructs: procedure SomeProc1(const coords: array of Double); cdecl; or PDouble = ^Double; procedure SomeProc2(const coords: PDouble; const high: Integer); cdecl; This allows seamless integration of Delphi functions with open arrays into C++ code and vice versa. I know that fpc does not like open array functions declared with cdecl. So I am wondering wath is the internal representation and are such functions binary equivalent to the above C++ example? For more information, see bug: http://www.freepascal.org/mantis/view.php?id=6940 Peter Popov -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply by email

Peter Popov
to ik

Are you saying that a delphi open array is binary compatible to a FPC open array?

Peter

Voodoo or not, code should be binary compatible.

ik wrote 55 lines
Hi, You should use PDouble = ^Double; procedure SomeProc2(const coords: PDouble; const high: Integer); cdecl; The reason is simple, it's equal to C's code... Open arrays are voodoo magic, specially for C\++ compilers.. Ido On 8/15/06, Peter Popov wrote: > Hi > I have the following question: how are open array parameters currently > implemented in FPC? The reason I am asking is that I am using DLL > functions in C which rely on borland's syntax, that is, > > void __cdecl SomeProc(const double *coords, const int high) (in > C++ Builder) > > is equivallet to either of the following Delphi constructs: > > procedure SomeProc1(const coords: array of Double); cdecl; > > or > > PDouble = ^Double; > procedure SomeProc2(const coords: PDouble; const high: Integer); cdecl; > > This allows seamless integration of Delphi functions with open arrays > into > C++ code and vice versa. > > I know that fpc does not like open array functions declared with cdecl. > So > I am wondering wath is the internal representation and are such > functions > binary equivalent to the above C++ example? > > For more information, see bug: > http://www.freepascal.org/mantis/view.php?id=6940 > > > Peter Popov > > -- > Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ > _______________________________________________ > fpc-devel maillist - > http://lists.freepascal.org/mailman/listinfo/fpc-devel > _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/mailman/listinfo/fpc-devel
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

Reply by email

Jonas Maebe
to Peter Popov: Hi I have the following question: how are open array parameters currently implemented in…
Peter Popov wrote 16 lines
I have the following question: how are open array parameters currently implemented in FPC? The reason I am asking is that I am using DLL functions in C which rely on borland's syntax, that is, void __cdecl SomeProc(const double *coords, const int high) (in C++ Builder) is equivallet to either of the following Delphi constructs: procedure SomeProc1(const coords: array of Double); cdecl; or PDouble = ^Double; procedure SomeProc2(const coords: PDouble; const high: Integer); cdecl;

It's the same in FPC. However as you say, that's "currently". You should not rely on internal implementations, it's a recipe for disaster.

Jonas

Reply by email

Michael Van Canneyt
to Peter Popov: Are you saying that a delphi open array is binary compatible to a FPC open array? Peter…
Peter Popov wrote
Are you saying that a delphi open array is binary compatible to a FPC open array?

No-one has investigated this, as far as I know.

Peter Voodoo or not, code should be binary compatible.

In order to work, yes.

But FPC code is not by definition binary compatible with Delphi's. Not always, at least.

Michael.

Show quoted text 70 lines
On Tue, 15 Aug 2006 09:47:18 +0200, ik wrote: > Hi, > > You should use > PDouble = ^Double; > procedure SomeProc2(const coords: PDouble; const high: Integer); cdecl; > > The reason is simple, it's equal to C's code... > > Open arrays are voodoo magic, specially for C\++ compilers.. > > Ido > > On 8/15/06, Peter Popov wrote: > > Hi > > I have the following question: how are open array parameters > > currently > > implemented in FPC? The reason I am asking is that I am using DLL > > functions in C which rely on borland's syntax, that is, > > > > void __cdecl SomeProc(const double *coords, const int high) (in > > C++ Builder) > > > > is equivallet to either of the following Delphi constructs: > > > > procedure SomeProc1(const coords: array of Double); cdecl; > > > > or > > > > PDouble = ^Double; > > procedure SomeProc2(const coords: PDouble; const high: Integer); > > cdecl; > > > > This allows seamless integration of Delphi functions with open arrays > > into > > C++ code and vice versa. > > > > I know that fpc does not like open array functions declared with > > cdecl. So > > I am wondering wath is the internal representation and are such > > functions > > binary equivalent to the above C++ example? > > > > For more information, see bug: > > http://www.freepascal.org/mantis/view.php?id=6940 > > > > > > Peter Popov > > > > -- > > Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ > > _______________________________________________ > > fpc-devel maillist - > > http://lists.freepascal.org/mailman/listinfo/fpc-devel > > > _______________________________________________ > fpc-devel maillist - > http://lists.freepascal.org/mailman/listinfo/fpc-devel -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply by email

Peter Popov
to Jonas Maebe: It's the same in FPC. However as you say, that's "currently". You should not rely on…

Well, what I mean is that C++ Builder specifically specifies how Delphi (Object Pascal) open array parameters should be viewed from C++. If this is the current FPC standard this is good. On the other hand FPC does not allow cdecl functions with open arrays (see
http://www.freepascal.org/mantis/view.php?id=6940), which is exactly what you would need to interface with a C++ library.

Peter

Jonas Maebe wrote 28 lines
On 15 Aug 2006, at 09:13, Peter Popov wrote: > I have the following question: how are open array parameters currently > implemented in FPC? The reason I am asking is that I am using DLL > functions in C which rely on borland's syntax, that is, > > void __cdecl SomeProc(const double *coords, const int high) (in C++ > Builder) > > is equivallet to either of the following Delphi constructs: > > procedure SomeProc1(const coords: array of Double); cdecl; > > or > > PDouble = ^Double; > procedure SomeProc2(const coords: PDouble; const high: Integer); cdecl; It's the same in FPC. However as you say, that's "currently". You should not rely on internal implementations, it's a recipe for disaster. Jonas _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/mailman/listinfo/fpc-devel
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

Reply by email

Jonas Maebe
to Peter Popov
Peter Popov wrote 6 lines
Well, what I mean is that C++ Builder specifically specifies how Delphi (Object Pascal) open array parameters should be viewed from C ++. If this is the current FPC standard this is good. On the other hand FPC does not allow cdecl functions with open arrays (see http://www.freepascal.org/mantis/view.php?id=6940), which is exactly what you would need to interface with a C++ library.

I agree with Ido the only proper way is to explicitly encode this view in your parameter declaration. There are more compilers than C+ +Builder and more Pascal compilers than just FPC (and more platforms than Win32/i386).

E.g. simply changing from a 32 to 64 bit platform may already break things otherwise (because e.g. the C "int" remains 32 bit while the implicit high parameter becomes 64 bit, or vice versa -- I don't know by heart what the size is of the high parameter on FPC 64 bit platforms, but I guess it's 64 bit).

Jonas

Reply by email