Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2012-03

Custom assignment operators

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Mark Morgan Lloyd

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?

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]
Sven Barth
to Mark Morgan Lloyd

Am 30.03.2012 17:40 schrieb "Mark Morgan Lloyd" <

: A few weeks ago somebody (Martin?) suggested I got round an endianness

issue by doing this:

Show quoted text 9 lines
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