[fpc-pascal] distinct types and type identifier

Peter Vreman peter at freepascal.org
Wed Jan 30 12:04:13 CET 2008


> On 30/01/2008, ik <idokan at gmail.com> wrote:
>> type
>>   TfpgColor = type longword;
>>
>> means that you have a new type in the same *range* of longword. That
>> means that you can assign the same number range, but if you have a
>> variable that is a longword, and you wish to assigned the value to a
>> TfpgColor, then you must cast it, or the compiler will tell you that
>> it expect a TfpgColor content (unless there is a bug ;)).
>
>
> Ah, okay. Now why can't they explain it like you just did, but in the
> help. :) Where could I add this explanation in the FPC docs?
>
> I think I'll use the type as define above from now onwards... That way
> we should always know what we are working with (TfpcColor in this
> case) when assigning values to variables etc.

In case of unique integer types. The types are not the equivalent, but are still compatible and
will be converted implicitly by the compiler. It unique types affect procedure overloading. The
following short example demonstrates this.

type
  TfpgColor = type longword;

procedure f(c:TfpgColor);
begin
end;

procedure f(l:longword);
begin
end;

procedure f2(l:longword);
begin
end;

var
  c : TfpgColor;
  l : longword;
begin
  c:=l;
  f(c);
  f2(c);
end.






More information about the fpc-pascal mailing list