[fpc-devel] Question on constref

Hairy Pixels genericptr at gmail.com
Wed Feb 1 13:48:40 CET 2023



> On Feb 1, 2023, at 5:56 PM, Adriaan van Os via fpc-devel <fpc-devel at lists.freepascal.org> wrote:
> 
> "A const parameter is be passed by reference or (for small-sized parameters) by value, whatever is most efficient. A constref parameter is guaranteed to be passed by reference in all cases. The latter is therefore typically used for interfacing with external code or when writing assembler routines."

I’ve been confused by constref versus const. I use constref when passing large records as parameters so I know it will not make needless copies but why doesn’t const function this way too? If the parameter is constant why would it ever make sense for the compiler to copy the entire record when it knows the function can’t change it?

Regards,
Ryan Joseph



More information about the fpc-devel mailing list