[fpc-pascal] Pointer question
pascaldragon at googlemail.com
Wed Aug 9 07:53:33 CEST 2023
Hairy Pixels via fpc-pascal <fpc-pascal at lists.freepascal.org> 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.
> TMyRec = record end;
> PMyRec = ^TMyRec;
> x: PByte;
> r: TMyRec;
> x := @r; // works
> x := PMyRec(@r); // fails
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).
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the fpc-pascal