compiler differences

This is a discussion on compiler differences within the C Programming forums, part of the General Programming Boards category; But how they do that and when is up to the implementors. Therefore, it is undefined, because no two implementations ...

  1. #16
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,538
    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.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  2. #17
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by creeping death View Post
    so whats keeping it from returning an error?
    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

  3. #18
    apprentiCe
    Join Date
    Oct 2008
    Location
    Hyderabad,India
    Posts
    136
    now this has confused me even more...

    have a look at this code

    Code:
    #include<unistd.h>
    #include<fcntl.h>
    #include<stdlib.h>
    
    int main()
    {
    
        if((write(STDIN_FILENO,"arrgh!",6))==-1)
        {
            perror("error writing to file");
        }    
    
    }
    this is the output
    Code:
    [c_d@localhost C scratchpad]$ gcc temp.c 
    [c_d@localhost C scratchpad]$ ./a.out 
    arrgh![c_d@localhost C scratchpad]$
    oO!! whats going on?
    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);

  4. #19
    apprentiCe
    Join Date
    Oct 2008
    Location
    Hyderabad,India
    Posts
    136
    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);

  5. #20
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    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.
    Code:
    fwrite("this",4,1,stdin);
    Does the same thing you just observed.

    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

  6. #21
    apprentiCe
    Join Date
    Oct 2008
    Location
    Hyderabad,India
    Posts
    136

    thanks

    Quote Originally Posted by MK27 View Post
    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?
    right
    But if the child wrote into it's own stdin (usually you would close that) the same thing will happen.
    Code:
    fwrite("this",4,1,stdin);
    Does the same thing you just observed.
    i guess...i need some time to imagine and grasp this...a few mins maybe, maybe a few hours...
    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.
    i got convinced right here...
    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.
    so only i agreed with you, in my previous post...
    Code:
    printf("%c%c%c%c%c%c%c",0x68,0x68^0xd,0x68|0x4,0x68|0x4,0x68|0xf,0x68^0x49,0x68^0x62);

  7. #22
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,538
    Quote Originally Posted by creeping death View Post
    i got convinced right here...
    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.
    so only i agreed with you, in my previous post...
    If stream points to an output stream .
    That means if it's an output stream. If it's an input stream, it needs to do no such thing. It's undefined.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #23
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by creeping death View Post

    i got convinced right here...
    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.
    so only i agreed with you, in my previous post...
    Yes, but that only happens if (a) stream points to an output stream and (b) there is any unwritten data for that stream. Since (a) stdin is not an output stream and (b) there shouldn't be any data waiting to be written to stdin, no write will happen.

  9. #24
    apprentiCe
    Join Date
    Oct 2008
    Location
    Hyderabad,India
    Posts
    136
    Quote Originally Posted by Elysia View Post
    If stream points to an output stream .
    That means if it's an output stream. If it's an input stream, it needs to do no such thing. It's undefined.
    oh come on!! that what i meant and said!!
    Code:
    printf("%c%c%c%c%c%c%c",0x68,0x68^0xd,0x68|0x4,0x68|0x4,0x68|0xf,0x68^0x49,0x68^0x62);

  10. #25
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,538
    Then what's the problem?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #26
    apprentiCe
    Join Date
    Oct 2008
    Location
    Hyderabad,India
    Posts
    136
    Quote Originally Posted by Elysia View Post
    Then what's the problem?
    nothing...its all good now!


    thanks for walking me though this...all you guys!!
    Code:
    printf("%c%c%c%c%c%c%c",0x68,0x68^0xd,0x68|0x4,0x68|0x4,0x68|0xf,0x68^0x49,0x68^0x62);

  12. #27
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,538
    Alright then. Good to know.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  13. #28
    apprentiCe
    Join Date
    Oct 2008
    Location
    Hyderabad,India
    Posts
    136
    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);

  14. #29
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,598
    Quote Originally Posted by creeping death
    when you guys say "C standard does not define..." what do you mean by "C standard"?

    ISO ,ANSI ,POSIX , M$?
    ISO (which is also ratified by ANSI).
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  15. #30
    apprentiCe
    Join Date
    Oct 2008
    Location
    Hyderabad,India
    Posts
    136
    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);

Page 2 of 3 FirstFirst 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 01:30 PM
  2. Compiler Paths...
    By Cobra in forum C++ Programming
    Replies: 5
    Last Post: 09-26-2006, 04:04 AM
  3. C Compiler and stuff
    By pal1ndr0me in forum C Programming
    Replies: 10
    Last Post: 07-21-2006, 11:07 AM
  4. I can't get this new compiler to work.
    By Loduwijk in forum C++ Programming
    Replies: 7
    Last Post: 03-29-2006, 05:42 AM
  5. how to call a compiler?
    By castlelight in forum C Programming
    Replies: 3
    Last Post: 11-22-2005, 10:28 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21