I experience a strange issue here with a small unit I made for an MWC random generator. The generator is an advanced record and provides two overloaded functions whose purpose should be obvious:
rand32i: dword; overload;
rand32i (range: dword): dword; overload;
The latter should return a random value in a range, and it calls the first version:
function TGenMWC.rand32i (const range: dword): dword;
begin
result := rand32i mod range; //adding brackets rand32i() solves the issue
end;
This works in mode delphi, but in mode objfpc the compiler complains that the function result might not be initialised; and in fact it seems that rand32i is never called, instead, the function always returns the same number, some garbage it found on the stack apparently. The compiler seems to confuse a function call with a variable; changing rand32i to rand32i() solves the issue.
Interestingly, when moving the entire code into a single program, the problem also disappears.
Tested with FPC3.2.0 and 3.2.3 of 2023/03/05, i386-win32.
Can someone please test before I file a bug report. Simply compile in mode objfpc and run. The random numbers generated by R.rand32i (1000) should not all be the same.