[fpc-pascal] passing "array of const" into cdecl procvar

Seth Grover sethdgrover at gmail.com
Fri May 13 17:58:40 CEST 2016


I'm having a little trouble figuring out how to do the following:

I have a procedural type defined as such:

===========================
type
  Tjson_pack = function(
    fmt : pchar;
    args : array of const)
    : pjson_t; cdecl;
===========================

I have a variable defined as:

===========================
_json_pack : Tjson_pack = nil;
===========================

And, finally, I have a local function declared this way:

===========================
function json_pack(
  fmt : pchar;
  args : array of const)
  : pjson_t;
begin
  if (_json_pack <> nil) then begin
    {$warning not sure how to handle this}
    result := _json_pack(fmt, args);
  end else begin
    result := nil;
  end;
end;
===========================

The error message I get when trying to compile is this:

Error: Wrong type "Array Of Const" in array constructor

If I try to make my local json_pack function cdecl, I get this:

Error: VarArgs directive (or '...' in MacPas) without
CDecl/CPPDecl/MWPascal and External

The reason I'm using a procedural type is because I'm loading the external
library at runtime via dynlibs:

===========================
_json_pack := Tjson_pack(dynlibs.GetProcAddress(JanssonLibHandle,
'json_pack'));
===========================

so I can't declare my function as external, since it's not. I can't declare
my procedural type as external, of course:

Error: Procedure directive "EXTERNAL" not allowed in procvar declaration

How can I do this? Is there any way for me to pass an array of const
argument through directly to a cdecl'ed procvar call?

(And yes, I know FPC has a built-in json engine... that's besides the point
:))

Thanks,

-Seth Grover
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20160513/4dba083b/attachment.html>


More information about the fpc-pascal mailing list