From e4ce7da0a207c15f2c9824cac8851a7fd8d68b31 Mon Sep 17 00:00:00 2001 From: George Koehler Date: Sun, 18 Sep 2016 00:07:30 -0400 Subject: [PATCH] Fix hilo.p for big-endian platforms. Unless it is packed, a Pascal char is a C int. Using C types, hilo.p passed an int *buf to uread(), which expected a char *buf. Then uread() wrote the char on the end of the int. This worked on little-endian platforms. This failed on big-endian platforms, as writing the value to the big end of an int multiplied it by 16777216. The fix is to use a packed array [0..0] of char in Pascal. I also change 'string' to a packed array, though this is not a necessary part of the fix. --- examples/hilo.p | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/examples/hilo.p b/examples/hilo.p index b13bbd1a0..be953a09e 100644 --- a/examples/hilo.p +++ b/examples/hilo.p @@ -8,7 +8,8 @@ program hilo(input, output); type - string = array [0..255] of char; + string = packed array [0..255] of char; + charstar = packed array [0..0] of char; var playing : Boolean; @@ -34,18 +35,18 @@ function random(range : integer) : integer; that conflicts with a Pascal keyword. Luckily there's a private function uread() in the ACK Pascal library that we can use instead. } -function uread(fd : integer; var buffer : char; count : integer) : integer; +function uread(fd : integer; var buffer : charstar; count : integer) : integer; extern; function readchar : char; var - c : char; + c : charstar; dummy : integer; begin - c := chr(0); + c[0] := chr(0); dummy := uread(0, c, 1); - readchar := c; + readchar := c[0]; end; procedure readstring(var buffer : string; var length : integer);