[fpc-devel] Bug in FPC and declaring distinct types
Graeme Geldenhuys
graemeg.lists at gmail.com
Thu Sep 18 11:31:24 CEST 2008
On Thu, Sep 18, 2008 at 10:11 AM, Michael Van Canneyt
<michael at freepascal.org> wrote:
>
> And it is also very annoying because
>
> Type
> MyString = type string;
>
> Const
> AString = 'something';
>
> Var
> M : MyString;
>
> begin
> M:=AString;
> end.
>
> Will no longer compile if you are too strict. They should at least remain
> assignment compatible.
That's the whole point - it shouldn't be assignment compatible. You
are creating a new MyString type, irrespective of what base-type it
was based on. Only MyString types should be assigned to MyString
types, otherwise you could simply have used String type.
I thought the example given in the delphi.non-technical discussion was
quite a good. Using mathematics and defining a Angle and Elevation
type. Both used the base-type Double. But in a math function you need
to know which one you are working with and what functions allow what
types (speaking of radians and degrees).
"Believe me, if you work with angles, one can easily confuse radians
and degrees (IOW, one can easily forget to convert between them),
especially if the user is used to using degrees, while the library
(sine, cosine, etc.) requires radians." -- Rudy Velthuis
Regards,
- Graeme -
_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/
More information about the fpc-devel
mailing list