Hi,
I just encountered some weird compiler behaviour while working on my test project for my UEFI bindings and wanted to share it here. It feels like a compiler bug but I don't want to jump the horse so quickly

The quick break down: I have a procedure for converting a UInt64 to a hexadecimal string and printing it via UEFI. The weird thing is that depending on the placement of another call to my Print function, only one character or all characters from my string are shown.
Snippet with correct behaviour:
procedure PrintHex(_int: UInt64);
const
MAX_DIGITS = 32;
DIGITS: array of WideChar = ('0','1','2','3','4','5','6','7','8','9','A','B','C',
'D','E','F');
var
wix, ix: Integer;
b: UInt8;
c: array [0..1] of WideChar;
_str: array [0..MAX_DIGITS] of WideChar;
begin
c[0] := '$';
c[1] := WideChar($0000);
wix := High(_str);
_str[wix] := WideChar($0000);
Dec(wix);
Print(@c[0]);
repeat
_str[wix] := DIGITS[_int mod 16];
_int := _int div 16;
Inc(ix);
Dec(wix);
until (_int = 0) or (ix >= MAX_DIGITS);
Print(PWideChar(_str) + wix);
end;
Snippet with incorrect behaviour:
procedure PrintHex(_int: UInt64);
const
MAX_DIGITS = 32;
DIGITS: array of WideChar = ('0','1','2','3','4','5','6','7','8','9','A','B','C',
'D','E','F');
var
wix, ix: Integer;
b: UInt8;
c: array [0..1] of WideChar;
_str: array [0..MAX_DIGITS] of WideChar;
begin
c[0] := '$';
c[1] := WideChar($0000);
Print(@c[0]);
wix := High(_str);
_str[wix] := WideChar($0000);
Dec(wix);
repeat
_str[wix] := DIGITS[_int mod 16];
_int := _int div 16;
Inc(ix);
Dec(wix);
until (_int = 0) or (ix >= MAX_DIGITS);
Print(PWideChar(_str) + wix);
end;
(If you want to see it in full context, the code is available
here)
EDIT: please also go easy on me, especially in regards to my code, i am very sleep deprived
