[fpc-pascal] array of const with cdecl procedure

Jonas Maebe jonas.maebe at elis.ugent.be
Sun Nov 11 21:31:13 CET 2012


On 11 Nov 2012, at 21:17, Bernd wrote:

> 2012/11/11 Jonas Maebe <jonas.maebe at elis.ugent.be>:
> 
>> Then you probably only read about i386 ABIs (and maybe m68k).
> 
> But a bunch of ifdefs should do the trick then, it should still be
> possible to implement every possible implementation in pascal somehow.

No, it is not possible. There are no Pascal (or C, for that matter) expressions that map to particular registers on entry into the function.

> Is there a document somewhere that specifies how exactly cdecl varargs
> is implemented on the different platforms?

There is one such document per ABI. These individual ABI documents are located all over the web. E.g. the official x86-64 ABI can be found at http://www.x86-64.org/documentation/abi.pdf, while the one for Win64 can be found at http://msdn.microsoft.com/en-us/library/ms235286.aspx

> I could no find anything.
> Since fpc can *call* vararg functions the knowledge about how exactly
> they are implemented on all the different platforms must exist
> somewhere?

It's much easier to construct it on the caller side than on the callee side. On the caller side, the information can be statically determined at compile time based on the types and order of the passed parameters. On the callee side, the information has to be dynamically determined. Moreover, the location of a cdecl varargs parameter generally depends on the number *and* types of the previous varargs parameters, so an expressions such as params[i] or even params[1] could never be supported. That's why in C you also have to use the va_start/va_arg/va_copy/va_end intrinsics to sequentially walk all such parameters.


Jonas


More information about the fpc-pascal mailing list