[fpc-devel] Abs(Variant) unexpected result
Michael Van Canneyt
michael at freepascal.org
Sun Feb 25 17:59:15 CET 2018
On Sun, 25 Feb 2018, Bart wrote:
> On Sun, Feb 25, 2018 at 5:34 PM, Michael Van Canneyt
> <michael at freepascal.org> wrote:
>
>>> So, would it be possible to have an overloaded Abs(V: Variant):
>>> Variant; function in the variants unit?
>>
>>
>> I advise against it.
>>
>> S : String;
>>
>> begin
>> S:='My very nice string';
>> S:=Abs(S);
>> end;
>>
>> Will then compile and give a run-time error, as opposed to a compile-time
>> error now.
>
> Did not think about that.
> Yeah, that's really bad.
>
> So, all we can do is let the compiler pick the float version for Abs(Variant)?
It seems so. Better yet, don't use variants.
They violate what Pascal stands for: type safety.
If you really _must_ use them, do any conversions explicitly.
Michael.
More information about the fpc-devel
mailing list