[fpc-devel] type question

Marc Weustink marc at dommelstein.net
Sat Oct 14 16:45:00 CEST 2006


Christian Iversen wrote:
> On Saturday 14 October 2006 15:55, Marc Weustink wrote:
>> Hi,
>>
>> if I define 2 types like:
>>
>> type
>>   MyA = type string;
>>   MyB = type string;
>>
>> are MyA and MyB considered as the same type ?
> 
> No, you are explicitly marking them as a new type. This is a very cool feature 
> of Pascal you wont find in many other languages.
> 
> (For instance, you could use it to create a new integer-type for little- and 
> big-endian numbers, ensuring that you _never_ directly assign a little-endian 
> number to a big-endian one, or vice versa)
> 
>> Should it be allowed to assign a variable of type MyA to a variable of
>> type MyB ?
> 
> No.
> 
>> IIRC, the use of = type <some type> creates a new type.
> 
> That's right.

OK, thanks for confirming my thoughts.
In an attempt to make some use of it, I tried the following, and it
compiles without a problem (also tried with Integer).
>From this it seems that for FPC it doesn't matter if it is "typed" or not.

Marc


program TypeTest;
{$mode objfpc}{$h+}

type
  TMyA = type String;
  TMyB = type String;

var
  A: TMyA;
  B: TMyB;
  S: String;

begin
  S := 'Some value';
  A := S;
  B := S;

  S := A;
  S := B;

  A := B;
  B := A;
end.





More information about the fpc-devel mailing list