Sign in Join

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

Mailing lists / fpc-pascal / 2019-09

Overloading Inc and Dec procedures?

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

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

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.

Reply by email

Sven Barth
to LacaK

LacaK schrieb am Mi., 18. Sep. 2019, 13:38:

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

Reply by email

LacaK
to Sven Barth
Show quoted text 12 lines
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.

Reply by email