[fpc-pascal] Documentation, syntax diagrams
Michael Van Canneyt
michael at freepascal.org
Wed Jan 8 22:08:11 CET 2014
On Wed, 8 Jan 2014, Howard Page-Clark wrote:
> On 08/01/2014 20:01, Sven Barth wrote:
>> On 08.01.2014 19:40, Howard Page-Clark wrote:
>>> On 08/01/2014 18:16, Jürgen Hestermann wrote:
>>>>
>>>> Today I found this type definition in some FreePascal sources:
>>>>
>>>> TypeReal =type Double;
>>>>
>>>> I wondered what the second “type” keyword means here (I have never seen
>>>> this before).
>>>
>>> You are being rather obtuse.
>>> Ignore the diagrams in the docs if they don't help you.
>>>
>>> The double use of type here simply means that the "Real" type is being
>>> defined as an alias for double. The two type identifiers now mean
>>> exactly the same thing as the "=" indicates.
>>
>> No, an alias would be
>>
>> === code begin ===
>>
>> type
>> Real = Double;
>>
>> === code end ===
>>
>> Using the "type" behind the "=" tells the compiler to declare a new type
>> based on the right side. So a "Double" and a "Real" are not assignment
>> compatible and can have different sets of operator overloads.
That is not quite correct.
They ARE assignment compatible, but can indeed have different sets of overloads.
As in the following example:
home: >./ta
Different types
home: >cat ta.pp
Type
TA = Integer;
TB = Type TA;
Var
A : TA;
B : TB;
begin
B:=1;
A:=B;
if TypeInfo(TA)<>TypeInfo(TB) then
Writeln('Different types');
end.
Michael.
More information about the fpc-pascal
mailing list