[fpc-pascal] Custom operators for non-record types

Sven Barth pascaldragon at googlemail.com
Mon Jul 2 09:54:19 CEST 2012


Am 02.07.2012 04:46, schrieb JC Chu:
> Do you have some inside information on the extra limitations regarding
> ordinal, floating point, and set types?
>
> As I understand, the only limitation on operator “overloading” should
> be that the operator do not have a default interpretation for the
> operands–result type combination.
>
> The modulus operator, for example, is certainly not defined by default
> as (Double, Double) → Double; but when I try to define it, the
> compiler says it’s an “[i]mpossible operator overload”.  The same goes
> for logical operators on enumeration types.  (Although each
> enumeration element has an underlying numerical value, it requires the
> use of Ord() or an explicit cast to convert it into a numerical type
> accepted by bitwise logical operators.)

The best source of information is the compiler source itself. The whole 
logic that decides whether an operator is overloadable or not is located 
in htypechk.pas, isoperatoracceptable and more imporantly also 
isbinaryoperatoroverloadable. From what I see everything is forbidden 
except what is written in there as an exception (and the ** operator 
which is always allowed).

> Maybe I should start preparing for a bug report?

Maybe there were reasons to not allow them... You can of course prepare 
a bug report or wait till one of the other developers who are more 
experienced in FPC's overloading speak up.

Regards,
Sven



More information about the fpc-pascal mailing list