[fpc-devel] Abs(Variant) unexpected result

Michael Van Canneyt michael at freepascal.org
Sun Feb 25 13:01:16 CET 2018



On Sun, 25 Feb 2018, Bart wrote:

> Hi,
>
> See: http://forum.lazarus.freepascal.org/index.php/topic,40223.msg277657/
>
> This seems rather unexpected.

Not really.

The abs() function is overloaded for different types.

The compiler does not know at compile time what type the variant is, 
how can you expect it to choose the "right" overloaded version ?

It probably takes the first fit for possible values in a Variant, 
which is most likely an integer version.

Don't use variants if you want type safety :)

Michael.



More information about the fpc-devel mailing list