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.
This commit is contained in:
parent
03b067e1d5
commit
e4ce7da0a2
|
@ -8,7 +8,8 @@
|
||||||
program hilo(input, output);
|
program hilo(input, output);
|
||||||
|
|
||||||
type
|
type
|
||||||
string = array [0..255] of char;
|
string = packed array [0..255] of char;
|
||||||
|
charstar = packed array [0..0] of char;
|
||||||
|
|
||||||
var
|
var
|
||||||
playing : Boolean;
|
playing : Boolean;
|
||||||
|
@ -34,18 +35,18 @@ function random(range : integer) : integer;
|
||||||
that conflicts with a Pascal keyword. Luckily there's a private function
|
that conflicts with a Pascal keyword. Luckily there's a private function
|
||||||
uread() in the ACK Pascal library that we can use instead. }
|
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;
|
extern;
|
||||||
|
|
||||||
function readchar : char;
|
function readchar : char;
|
||||||
var
|
var
|
||||||
c : char;
|
c : charstar;
|
||||||
dummy : integer;
|
dummy : integer;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
c := chr(0);
|
c[0] := chr(0);
|
||||||
dummy := uread(0, c, 1);
|
dummy := uread(0, c, 1);
|
||||||
readchar := c;
|
readchar := c[0];
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure readstring(var buffer : string; var length : integer);
|
procedure readstring(var buffer : string; var length : integer);
|
||||||
|
|
Loading…
Reference in a new issue