[fpc-pascal] Integer = Extended?

Daniël Mantione daniel.mantione at freepascal.org
Thu May 17 08:22:22 CEST 2007



Op Thu, 17 May 2007, schreef Wolfram Kläger:

> What?s wrong with the following declarations:
> 
> function Any(A1 : Extended; A2 : Extended) : AnyType; overload;
> 
> function Any(A1 : Integer; A2 : Integer) : AnyType; overload;
> 
> FPC 2.04 on Win32 says, both functions have same parameter list. Consequently, there is no error message, when I?m feeding the extended version with Integers.
> 
> Say, such autocast is a convenience feature in many cases. For my application it?s weird. What is the appropriate workaround? Is there some homemade type checking like
> 
> if A1 is Integer then SureItsInteger else SureItsExtended?

Use exact matching parameters. FPC will try to do as little type 
conversions as possible, so if you feed your procedure with integers it 
won't call the extended version. If you want to call the extended version, 
convert the parameters to extended first.

It is however good practise to make both variants have the same semantics.

Daniël


More information about the fpc-pascal mailing list