But how they do that and when is up to the implementors. Therefore, it is undefined, because no two implementations may do it the same.
Printable View
But how they do that and when is up to the implementors. Therefore, it is undefined, because no two implementations may do it the same.
Again, the spec says "if stream is an output stream...shall cause to be written to the file."
After reading that, why would you still believe that calling fflush(stdin) would mean by necessity a write operation? You would be better to assume that that this command might do absolutely nothing, or that the reason it may appear to work is that the the file pointer advances by the size of the unwritten data.
Maybe it should be an error, but on the other hand there could be overkill vis. checking to make sure a command is used appropriately, which if you think of fflush() as something that "flushes" downstream, using fflush(stdin) in the first place is nonsensical.
now this has confused me even more...
have a look at this code
this is the outputCode:#include<unistd.h>
#include<fcntl.h>
#include<stdlib.h>
int main()
{
if((write(STDIN_FILENO,"arrgh!",6))==-1)
{
perror("error writing to file");
}
}
oO!! whats going on?Code:[c_d@localhost C scratchpad]$ gcc temp.c
[c_d@localhost C scratchpad]$ ./a.out
arrgh![c_d@localhost C scratchpad]$
i told to write to stdin!!! how is it writing to stdout?!
so does this mean that...whatever we would try to write to stdin...would be written to stdout???......i guess,here its implement in this way...
so if that is the case...then the command fflush(stdin) is not "undefined" really...it would try to write to stdin but end up writing to stdout!!
any thoughts on this one people??
i agree that fflush(stdin) is nonsensical...but, isn't my terminals behaviour most unexpected?
Keep in mind each process has it's own stdin and stdout. If you had a forked process connected to a parent with a pipe, you write into the stdin of the pipe and it comes out of the stdout of the pipe, right? But if the child wrote into it's own stdin (usually you would close that) the same thing will happen.
Does the same thing you just observed.Code:fwrite("this",4,1,stdin);
But, once again, the standard does not say that fflush(stdin) will write to anything to anywhere, which you still seem convinced this is happening.
right
i guess...i need some time to imagine and grasp this...a few mins maybe, maybe a few hours...Quote:
But if the child wrote into it's own stdin (usually you would close that) the same thing will happen.
Does the same thing you just observed.Code:fwrite("this",4,1,stdin);
i got convinced right here...Quote:
But, once again, the standard does not say that fflush(stdin) will write to anything to anywhere, which you still seem convinced this is happening.
so only i agreed with you, in my previous post...:)Code:If stream points to an output stream or an update stream in
which the most recent operation was not input, fflush() shall
cause any unwritten data for that stream to be written to the
file, and the st_ctime and st_mtime fields of the underlying
file shall be marked for update.
Then what's the problem?
Alright then. Good to know.
ummm............hi! just one more doubt....
when you guys say "C standard does not define..." what do you mean by "C standard"?
ISO ,ANSI ,POSIX(IEEE) , M$?
ISO (which is also ratified by ANSI).Quote:
Originally Posted by creeping death
i see. thanks