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

Sven Barth pascaldragon at googlemail.com
Sun Jul 1 21:41:11 CEST 2012


On 01.07.2012 17:39, JC Chu wrote:
> In Delphi mode, each custom operator has to be associated with a
> record type, and must take or return such a record.  It seems that the
> OBJFPC mode doesn’t have this restriction; for example, the Math unit
> exports a custom ** on Int64, which is a simple type.

Global operator declarations were forbidden for mode Delphi as Delphi 
does not support them either (you can use them in Delphi modes though 
even if they were declared in non-Delphi modes). Global operators 
existed in FPC before Delphi introduced their operators in records concept.

> However, I’ve been unable to define operators other than ** for
> non-record types, even if they do not conflict with the default
> interpretation.  Examples include OPERATOR MOD (x, m: Double): Double
> and OPERATOR AND (x, y: Tristate): Tristate, where Tristate is an
> enumeration type.
>
> Is this a bug, or is there any explanation for this?

Some parameter combinations are not allowed, because certain inline 
operators are already in place. I don't know their exact rulings, but 
ordinals (Integer values, floating point values), enums and sets are a 
bit restricted regarding overload (especially if it is a binary operator 
where left and right is of such a type).

It's best you simply try whether it's supported and if not you need to 
look for a different method... (or ask on the list why it's not allowed)

Regards,
Sven



More information about the fpc-pascal mailing list