Overloading Inc and Dec procedures?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Overloading Inc and Dec procedures?

LacaK
Hi *,

seems, that overloading of Inc, Dec internal compiler procedures is not
allowed.
Is it by intention or can it be fixed (adding overload keyword to system
function definitions?).

I would like to add support for:

   procedure Inc(var a: integer; b: single); overload; inline;
   begin
     a := a + Round(b);
   end;
   procedure Inc(var a: single; b: single); overload; inline;
   begin
     a := a + b;
   end;
   procedure Dec(var a: integer; b: single); overload; inline;
   begin
     a := a - Round(b);
   end;
   procedure Dec(var a: single; b: single); overload; inline;
   begin
     a := a - b;
   end;

But nor this approach nor operator overloading is allowed.
(Error message: Wrong number of parameters specified for call to "Inc"
is emited , when simple Inc(a); is used
I can avoid this error by prefixing System.Inc(), but it will require
change on many places in code)

I need use addition or subtraction on operands, which left of them can
be either "integer" or "single" type (specialized generic type)

Example:

var x,y: TAnyNumericType; x1,y1: single; i: integer;
Inc(x, x1); // x,y can be either integer or single
Inc(y, y1);
Inc(i); // Error: Wrong number of parameters specified for call to "Inc"

TIA

-Laco.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Overloading Inc and Dec procedures?

Free Pascal - General mailing list
LacaK <[hidden email]> schrieb am Mi., 18. Sep. 2019, 13:38:
Hi *,

seems, that overloading of Inc, Dec internal compiler procedures is not
allowed.
Is it by intention or can it be fixed (adding overload keyword to system
function definitions?).

Yes, this is by intention and no, it can't be fixed.

Regards, 
Sven 

_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Overloading Inc and Dec procedures?

LacaK




Hi *,

seems, that overloading of Inc, Dec internal compiler procedures is not
allowed.
Is it by intention or can it be fixed (adding overload keyword to system
function definitions?).

Yes, this is by intention and no, it can't be fixed.

Thank you!

Can it be then somewhere documented?

L.



_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal