[fpc-pascal] callback from c with varargs

Luca Olivetti luca at ventoso.org
Sat Dec 19 22:35:45 CET 2020


Hello,

I'm trying to use a c library where I can define a logging plugin.

The c prototype for the callback is

     void (*log)(void *logContext, UA_LogLevel level, UA_LogCategory 
category, const char *msg, va_list args);


however I couldn't find a way to define a suitable callback in fpc since 
the "array of const" construct is not allowed with cdecl without 
external, i.e.

procedure LogLog(logContext: Pointer; level: UA_LogLevel; category: 
UA_LogCategory; msg: PAnsiChar; const args:array of const);cdecl;

gives an error "Error: VarArgs directive (or '...' in MacPas) without 
CDecl/CPPDecl/MWPascal/StdCall and External".

I cannot add "external" (I don't want to call an external function, it's 
the library calling my function) or remove the cdecl (parameter passing 
wouldn't work then).

Is there some trick to define a function with varargs callable from the 
c library?

Bye
-- 
Luca


More information about the fpc-pascal mailing list