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.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
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!!
Last edited by creeping death; 03-29-2009 at 02:09 PM.
Code:printf("%c%c%c%c%c%c%c",0x68,0x68^0xd,0x68|0x4,0x68|0x4,0x68|0xf,0x68^0x49,0x68^0x62);
any thoughts on this one people??
i agree that fflush(stdin) is nonsensical...but, isn't my terminals behaviour most unexpected?
Code:printf("%c%c%c%c%c%c%c",0x68,0x68^0xd,0x68|0x4,0x68|0x4,0x68|0xf,0x68^0x49,0x68^0x62);
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.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
right
i guess...i need some time to imagine and grasp this...a few mins maybe, maybe a few hours...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...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.
Code:printf("%c%c%c%c%c%c%c",0x68,0x68^0xd,0x68|0x4,0x68|0x4,0x68|0xf,0x68^0x49,0x68^0x62);
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$?
Last edited by creeping death; 03-29-2009 at 10:35 PM.
Code:printf("%c%c%c%c%c%c%c",0x68,0x68^0xd,0x68|0x4,0x68|0x4,0x68|0xf,0x68^0x49,0x68^0x62);
ISO (which is also ratified by ANSI).Originally Posted by creeping death
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
i see. thanks
Code:printf("%c%c%c%c%c%c%c",0x68,0x68^0xd,0x68|0x4,0x68|0x4,0x68|0xf,0x68^0x49,0x68^0x62);