[fpc-devel] "Default" discussion for SmartPointers etc
Michael Van Canneyt
michael at freepascal.org
Wed Jul 27 10:38:00 CEST 2016
On Wed, 27 Jul 2016, Maciej Izak wrote:
>
> 3. "default" need to be transparent and usable with existing code base,
> some compiler magic is part of my further compiler development (I mean here
> "Storage Modifiers" and ARC objects in DelphiNextgen mode). With current
> approach is possible to pass record with default field as var/out/constref
> parameter. With property that is impossible.
This is probably the only good argument.
>>
>> Question: can "default" only be used in "record" or also in "object" and
>> "class"?
>>
>
> Current implementation allows "default" only for "records".
I don't think that for classes this should be allowed.
Imagine:
TSomeClass = Class
Property SomeProp : TSomeClass; default;
end;
Var
A,B : TSomeClass;
begin
A:=B; // What to do ? Set A, or A.SomeProp ?
end;
For records, this construct is simply not possible.
> @@ operator is very simple way to determine where you point. In any other
> case we have casting hell. See below (and more below). @@ exist rather as
> fulfillment to pa := @a; form tdefault7.pp (anyway is necessary for untyped
> pointers). You might not like @@ operator but @@ is part of long tradition.
> In practice works like a charm and is very clear.
I agree and think @@ is indeed better.
>
>
>> Since normally in Pascal the
>> result type of an expression is *not* determined by the left hand side
>> of an assignment that's rather confusing (yes, there are exceptions, but
>> that doesn't mean that one needs to add a new one).
>>
>
> That is also by design. That is because you can't declare as "default
> field" nor "normal field" the field of owner type, so as logical
> consequence the syntax needs to be allowed (I mean here pa := @a; form
> tdefault7.pp). In daily usage it works very well and any other compiler
> behavior is irrational.
? A compiler always behaves rational.
Michael.
More information about the fpc-devel
mailing list