[fpc-devel] Bug in FPC and declaring distinct types
Florian Klaempfl
florian at freepascal.org
Thu Sep 18 11:34:55 CEST 2008
Graeme Geldenhuys schrieb:
> 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.
It's as useless as any talk in this newsgroup. If you don't like two
types being assignment compatible, use classes, records whatever.
> 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
See above.
More information about the fpc-devel
mailing list