[fpc-pascal] Custom assignment operators

Sven Barth pascaldragon at googlemail.com
Fri Mar 30 23:43:13 CEST 2012


Am 30.03.2012 17:40 schrieb "Mark Morgan Lloyd" <
markMLl.fpc-pascal at telemetry.co.uk>:
>
> A few weeks ago somebody (Martin?) suggested I got round an endianness
issue by doing this:
>
> type    WordLE= packed record b0, b1: byte; end;
>
> operator := (wle: WordLE): word;
>
> begin
> ..
>
> It works well, except that attempting to use an assignment inside the
operator definition immediately recurses: I've fixed this by using Move(),
with operand sizes check by assertion.
>
> Is it possible to tell the compiler that, for a code fragment like this,
it is under no circumstances to attempt any implicit type conversions?

No, there is no possibility. But why dies it try to do a type conversion in
the first place? Can you show your code please?

Also operator overloads should be considered "from great power comes great
responsibility".

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20120330/cca129e6/attachment.html>


More information about the fpc-pascal mailing list