Sign in Join

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

Mailing lists / fpc-devel / 2011-09

who can explain why array of const can't be passed to another array of const

4 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

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

Paul Ishenin

Hello devs.

Please explain why the next example does not compiles with a message: "Error: Wrong type "Array Of Const" in array constructor"?

program Project1;
{$mode delphi}{$H+}
function g_object_dosomething(AObject: Pointer; args: array of const):
Boolean; cdecl; external 'test.dll';
type
   TGObject = object
      function DoSomething(args: array of const): Boolean; stdcall;
   end;
function TGObject.DoSomething(args: array of const): Boolean; stdcall;
begin
   g_object_dosomething(@self, args);
end;
begin
end.

If I change "cdecl" to "stdcall" in g_object_dosomething then it compiles with no error.

For me it is strange. Should developer care about internal compiler representation of an "array of const" for different conventions? Imo this is a compiler task.

I've checked the same on delphi XE and there it compiles.

So whether this is 1)a bug 2)unimplemented feature 3)desired compiler behavior?

Best regards,
Paul Ishenin.

Reply by email

Jonas Maebe
to Paul Ishenin
Paul Ishenin wrote 5 lines
If I change "cdecl" to "stdcall" in g_object_dosomething then it compiles with no error. For me it is strange. Should developer care about internal compiler representation of an "array of const" for different conventions?

It's more that even though both are called "array of const", they are completely different things. They also don't support the same types.

Show quoted text 6 lines
Imo this is a compiler task. I've checked the same on delphi XE and there it compiles. So whether this is 1)a bug 2)unimplemented feature 3)desired compiler behavior?

You could say it is an unimplemented feature, but implementing it would require a lot of assembler code that's different for every architecture (and in some cases also for different OSes, since not all OSes use the same ABI and the ABI defines how C varargs must be passed). It is not a bug since the error message is given on purpose.

Jonas

Reply by email

Alexander Klenin
to Jonas Maebe
Jonas Maebe wrote
It's more that even though both are called "array of const", they are completely different things. They also don't support the same types.

Perhaps varargs-compatible parameter type should be called something else then?

Alexander S. Klenin

Reply by email

Jonas Maebe
to Alexander Klenin
Alexander Klenin wrote 7 lines
On Wed, Sep 14, 2011 at 19:03, Jonas Maebe wrote: > It's more that even though both are called "array of const", they are > completely different things. They also don't support the same types. Perhaps varargs-compatible parameter type should be called something else then?

Both backwards and Delphi compatibility stand in the way of that.

Jonas

Reply by email