[fpc-pascal] Integer = Extended?

2007-05-16 Thread 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?

Wolfram
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Integer = Extended?

2007-05-16 Thread Daniël Mantione


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___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal