This kind of blows my mind.
So, I have a procedure
procedure swapIntegers(var i :integer; var j:integer); // can I just write var i,j here? I know you can when not passing by reference
var tmp : integer;
begin
tmp := i;
i := j;
j := tmp;
end;
it works great inside of one of my units. I then decided that this really can be used in many different cases, so I moved it to a "useful functions" unit, but then I get the error after writing the procedure in the interface section of the "useful functions" unit and importing it. The error is
Error: Call by var for arg no. 2 has to match exactly: Got "LongInt" expected "SmallInt"
but here's the thing: this error doesn't happen if I define the function inside my unit. So the operation of importing the function inherently changes the accepted arguments somehow?
Please note that, maybe there is a better procedure for this thats's already defined, but I get the same error for procedures with a call by reference which have only one argument, and my only solution was to rewrite those procedures in the unit that I was using. So I need a solution to the error not a workaround for this specific case.
Thanks!
Edit: Switched j:=i to j:=tmp
SOLUTION: The error here was that the imported files were compiling in fpc mode by default while my code was in objfpc. objfpc has integers as longints while fpc has integers as smallint.
{$MODE OBJFPC}{H+}
before the interface switches it to objfpc.
https://www.freepascal.org/docs-html/prog/progap4.html
will show you the differences between the modes.