Re: [fpc-pascal] Does the varargs specifier behave differently on 32 and 64 bit platforms?

2024-01-05 Thread Jonas Maebe via fpc-pascal

On 05/01/2024 14:38, Thomas Kurz via fpc-pascal wrote:


The CDECL calling convention should pass all arguments on the stack


It does not do that in all (or even most) cases. The CDECL calling 
convention passes arguments according to what the platform's ABI prescribes.


For Windows/x64, that is documented here: 
https://learn.microsoft.com/en-us/cpp/build/x64-calling-convention?view=msvc-170#varargs



Jonas
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] Does the varargs specifier behave differently on 32 and 64 bit platforms?

2024-01-05 Thread Thomas Kurz via fpc-pascal
Hello,

I'm using a declaration like this

TYPE TRSMControl = FUNCTION (AData: PtrInt): PtrInt; CDECL; VARARGS;
VAR RSMControl: TRSMControl;

to make calls to a DLL function which expects a variable number of arguments. 
For example:

RSMControl (PtrInt(1), PtrInt(2), PtrInt(3))

On win32, this works fine. On win64, I get only the first argument correctly, 
the rest is garbage. Within the DLL, I subsequently access all parameters by 
taking the address of the first parameter and incrementing it in steps of 4 
bytes (or 8 bytes on win64).

I wonder whether I'm doing something wrong on the caller or callee side. The 
code worked reliably on win32, but I'm now trying to target win64 and am facing 
the problem that I cannot access the data that were passed. The CDECL calling 
convention should pass all arguments on the stack, and I expect subsequent 
arguments to be at subsequent memory addresses.

Does anyone have a clue for me?

Kind regards,
Thomas

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal