[fpc-devel] cdecl and constant parameters
Jonas Maebe
jonas.maebe at elis.ugent.be
Wed Mar 31 22:05:25 CEST 2010
On 31 Mar 2010, at 20:01, Seth Grover wrote:
> The documentation
> (http://www.freepascal.org/docs-html/ref/refsu56.html) says "A
> constant argument is passed by reference if its size is larger than a
> pointer. It is passed by value if the size is equal or is less then
> the size of a native pointer."
>
> I have a packed record type defined which contains two 64-bit integers
> (so it's obviously bigger than a pointer). I wrote a routine that
> takes one of these records as a constant argument (eg., "procedure
> Doit(const rec : TMyRecord);")
>
> I compiled it and looked at the assembly being generated, and sure
> enough it was being passed by reference, just as the documentation
> says. However, if the procedure is declared as "cdecl" the record
> itself (its contents) are copied onto the stack.
>
> Should the documentation be updated? Or is this incorrect behavior?
I personally think that the documentation should not say anything at all about how "const" parameters are passed, as this should be an implementation detail that nobody should care about.
That said, with "cdecl", "const" has the same meaning as it has in C, which is "pass the argument exactly the same way as when there is no const modifier".
Jonas
More information about the fpc-devel
mailing list