Hairy Pixels via fpc-pascal schrieb am
Mi., 9. Aug. 2023, 04:59:
> I just noticed this by accident and I don't understand. Why does " x :=
> @r; " compile? I would expect it to fail like the next line where I cast to
> the explicit type.
>
> type
> TMyRec = record end;
> PMyRec = ^TMyRec;
> var
> x: PByte;
> r: TMyRec;
> begin
> x := @r;// works
> x := PMyRec(@r); // fails
> end.
By default @ returns a *untyped* pointer that can be assigned to any
pointer type. Thus is compatible with Delphi and can be controlled with the
$TypedAddress directive (there's a slight exception to this when you assign
a pointer to a function to a function variable (etc) or pass it to such a
parameter, because the compiler has to pick the correct overload if there
are multiple functions with the same name in scope).
Regards,
Sven
>
___
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal