Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: XP bug? (code fragment)

Author: Bas Hamstra

Date: 12:56:24 08/27/04

Go up one level in this thread


On August 27, 2004 at 15:41:33, Bas Hamstra wrote:

>On August 27, 2004 at 15:07:28, Gerd Isenberg wrote:
>
>>On August 27, 2004 at 14:58:56, Gerd Isenberg wrote:
>>
>>>On August 27, 2004 at 14:28:06, Bas Hamstra wrote:
>>>
>>>>The following program gives me other output in XP than under previous windows
>>>>versions:
>>>>
>>>>#include <stdio.h>
>>>>#include <conio.h>
>>>>
>>>>int main(int argc, char* argv[])
>>>>{       char Buf[16] = {0};
>>>>
>>>>        setbuf(stdin, NULL);
>>>>
>>>>        while(1)
>>>>        {   if(kbhit() )
>>>>            {   gets(Buf);
>>>>                printf("Received: %s\n", Buf);
>>>>            }
>>>>        }
>>>>        return 0;
>>>>}
>>>>
>>>>Output:
>>>>
>>>>aaa
>>>>Received: Paa
>>>>
>>>>So, if after typing aaa the first character seems to go lost. I am pretty
>>>>certain that under Win98 it worked like intended. Is this a bug?
>>>>
>>>>(I am using XP with Borland C++ Builder 4.0)
>>>>
>>>>Bas.
>>>
>>>
>>>with msc6 under XP i get
>>>aaa  (or any other sequence)
>>>Received: d
>>>
>>>Seems that stdin does not work unbuffered.
>>>
>>>Gerd
>>
>>
>>from
>>
>>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/HTML/_crt_setbuf.asp
>>
>>...
>>
>>setbuf has been replaced by setvbuf, which is the preferred routine for new
>>code. setbuf is retained for compatibility with existing code.
>
>Yes, that seems to solve the problem... Thanks Gerd.
>
>Bas.

Oops, NOT.

#include <stdio.h>
#include <conio.h>

int main(int argc, char* argv[])

{       char Buf[16] = {0};

        setvbuf(stdin, NULL, _IONBF, 0);

        while(1)
        {   if(kbhit() )
            {   gets(Buf);
                printf("Received: %s\n", Buf);
            }
        }
}

Output:

aaa
Received: Paa

So the same behaviour as with setbuf. This worked ok under W98 for years... This
bug appears only when I run Tao in textmode. A search-interrupt then calls
kbhit() now and then, to check for input. However with redirected input
PeekNamedPipe() in stead of kbhit() is used, so no problem there.

Bas.






This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.