[fpc-pascal] Integer = Extended?

ik idokan at gmail.com
Thu May 17 14:43:52 CEST 2007


On 5/17/07, Wolfram Kläger <wolfram.klaeger at web.de> wrote:
>
> > -----Ursprüngliche Nachricht-----
> > Von: FPC-Pascal users discussions <fpc-pascal at lists.freepascal.org>
> > Gesendet: 17.05.07 08:21:54
> > An: FPC-Pascal users discussions <fpc-pascal at lists.freepascal.org>
> > Betreff: Re: [fpc-pascal] Integer = Extended?
>
>
> >
> >
> >
> > 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
>
>
> Thank you, Daniel.
>
> Must have been for some other reason. Could not reproduce the error. So I am happy again, that I can rely on type checks in Pascal, as I am used to.
>
> But what about the homemade type check, anyway? Dealing with classes, I know how to use 'is', e.g. if myclass is TMyClass then ... Is there any similar construct for 'if x is Integer then .. else ...'?
>
> Finally I agree in general, regarding good practice. But my application is about image processing. The overloaded methods are for resizing images. The extended version accepts relative input, say in percent, the integer version expects absolute pixel size. I thought itŽs a good idea, to call all such methods by the same name, stressing the compilerŽs overload feature a bit.
>
> Wolfram

I think Generics can solve some of the issues (but I'm only guessing),
however I do not know yet how the generics on FPC works (any guides
ppl ?).

Ido
-- 
http://ik.homelinux.org/


More information about the fpc-pascal mailing list