Hallo dear Hackers, hi Peter,
I found a bug in GPC (my version: 970401/linux/i586)?
I wrote the following little program:
{ -- the buggy program - see below ----------------}
{Warning getchar may be implemented as a macro to getc(stdin), so this may be, this will not work for you }
program test1(input,output);
function getchar:integer; C;
var k:integer;
begin k:=getchar; while (k<>-1) do begin writeln(k); k:=getchar; end; end.
{--- The same as C-Source -- works ok. ---}
#include <stdio.h>
void main() { int k; k=getchar; while (k!=-1) { printf("%i\n",k); k=getchar; } }
{ --------------------------------------- }
Ok. Compiling test1.pas - no errors. Running test1 Enter an 'N' press return you will see '78 10' - thats right.
Now the following:
echo "N">data test1 <data
Now you will see '10' - thats wrong. test1 has eaten up the first char.
(Doing the same with the compiled C-Source gives '78 10', the correct result.)
It does not even help to compile a readkey.o from a C-Source and use the Readkey procedure from that. Obviously Gpc-Runtime does something strange at startup. In real live my stdin will be connected to a socket so that's not easy to be worked around.
Quick responses appreciated.
thanks
Sven