[fpc-pascal] A better way?

Sven Barth pascaldragon at googlemail.com
Fri Apr 15 14:01:28 CEST 2016

Am 15.04.2016 11:22 schrieb "Dennis" <dec12 at avidsoft.com.hk>:
>> > You could describe it as typecast done in the var clause of a method.
The right hand identifier is not restricted to function parameters.
>> While it works using "absolute" for a public API is rather unsafe (I'd
only use that in private methods). In those cases the "as" operator should
he used (or at least "is" plus returning an error).
>> Regards,
>> Sven
> May I know why it is unsafe to use absolute on public method's parameters?

I didn't mean that in the context of the "public" section of classes, but
if your API is available to third party users (that can also include other
members of the same development team) then you need to make sure that the
instance that is passed in is indeed a correct one as otherwise you'd
access the wrong fields or methods. For this kind of mistake public and
protected methods are of course the most affected ones as are routines that
are declared in the interface section of a unit.

> Also, will there be any compiler options in which the parameters are
passed through registers?  In that case, will the absolute of private
method's parameters still work?

Parameters are already often passed in registers (of course this depends on
the platform). However parameters also often have a spilling locations in
the stack to store the parameter if register pressure gets too high, so
absolute shouldn't be a problem normally. It might also be that the usage
of absolute prohibits some optimizations the compiler would otherwise do
with that parameter inside the function.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20160415/b808b251/attachment.html>

More information about the fpc-pascal mailing list