Mail Archives: djgpp-workers/1999/04/06/23:00:04
Bonjour
> > It's the same as doing i = i++; // undefined behavior.
>
> Your example is specious at best.
>
It is right on target, it describes an undefined behavior
that no STDs make promises on.
They are both compiler/library/system/whatever specific.
> >
> > IMO, it is ill-advise to allow fflush() on an input stream even
> > if at first it may look like a usefull extension.
> >
>
> And I disagree. Certainly no change there.
>
> Suppose we define fflush(FILE *stream) as
>
> flush the buffer associated with the stream
>
> If it is decided that fflush() on an input stream should be defined,
> how will that affect your work?
It will not, I try to avoid non-portable code.
Usually when people do fflush(stdin), they want to discard the
input keyboard. A portable way maybe
tcflush(STDIN_FILENO, TCIFLUSH);
or just plain
int c;
do {
c = getchar();
} while (c != EOF && c != '\n');
But if you want to do implement it;
int fflush (FILE * stream)
{
.....
if (stream)
{
int fd = fileno(stream);
/* discard the allocated library buffer */
....
/* discard whatever the system/device had */
if (isatty(fd))
{
tcflush(fd, TCIFLUSH);
tcflush(fd, TCOFLUSH);
}
.....
}
...
}
But this not as trivial as you may think.
--
au revoir, alain
----
Aussi haut que l'on soit assis, on est toujours assis que sur son cul !!!
- Raw text -