fflush(stdin) and other odd topics

This is a discussion on fflush(stdin) and other odd topics within the A Brief History of Cprogramming.com forums, part of the Community Boards category; XErath, often standards will leave constructs undefined in order for implementors to define them. For instance, 4/0 may be undefined ...

  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    470

    fflush(stdin) and other odd topics

    XErath, often standards will leave constructs undefined in order for implementors to define them. For instance, 4/0 may be undefined for some language, but an implementor might want throw some exception when divide by 0 occurs. The value of sizeof(int), like above, isn't defined by the standard, but by the implementorl. So, when Microsoft defines what fflush(stdin) does, there's no problem; it's what the definition leaves out--that it's non-standard--which might be problem. But this is the fault of the documention not the compiler, and because most go to the compiler pages to learn about what the compiler does it's not too much of a problem, I think.

    Microsoft what ?!? You're joking right ?!?
    This is a piece of code from browser.js from Opera

    // Fixing MSDN
    // Problem: very IE-centric scripting, excludes other browsers with sniffing
    // Credits: Tarquin
    if( location.href.indexOf('http:\/\/msdn.microsoft.com\/workshop\/') == 0 ) {
    //more 70 lines of code
    Perhaps MS tried to detect IE and mozilla versions great enough to run the site but forgot opera?
    Last edited by okinrus; 07-07-2005 at 02:12 AM. Reason: the value of sizeof(int) and cleanup

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Is there some reason this is a topic of its own and not a PM, or in the thread you're actually talking about?


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Aug 2003
    Posts
    470
    xErath told me to start a new thread. So I'm replying to XErath but anyone else can comment.

  4. #4
    Registered User
    Join Date
    Jun 2004
    Posts
    722
    As I've said before to someone else. This is want I meant.
    I'm simply saying that if anyone provides writes fflush(stdin) in its source, that source will become MSVC++ specific, and not portable. Each compiler may provide its extensions. Each programmer can choose each extensions to use, but he/she should choose carefully if portability is a issue.
    Webpages are open to all, and viewed by any browser, therefore, webpages must conform to standards.
    Again
    Perhaps MS tried to detect IE and mozilla versions great enough to run the site but forgot opera?
    This has to be a joke.
    http://en.wikipedia.org/wiki/Microsoft#Business_culture
    All the sudden microsoft started to worry about other browsers?!? They don't even care about theirs.
    http://en.wikipedia.org/wiki/http://...wsers#Security
    Code:
    Ranking Browser	          Number of known vulnerabilities Oldest known vulnerability
    12      Internet Explorer 92                              April 18, 2001

  5. #5
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Quote Originally Posted by okinrus
    So, when Microsoft defines what fflush(stdin) does, there's no problem; it's what the definition leaves out--that it's non-standard--which might be problem. But this is the fault of the documention not the compiler, and because most go to the compiler pages to learn about what the compiler does it's not too much of a problem, I think.
    I like Chris Torek's "cost-benefit analysis" description. And I'd say the issue is with the programmer.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  6. #6
    C Programmer Stack Overflow's Avatar
    Join Date
    Apr 2004
    Posts
    477
    Hello,

    This is a good thread. Through my research of the standard function fflush(), I've realized that it is taken out of context by alot of programmers. For instance, this MSDN article explains fflush() briefly. The Remarks explained there are close to accurate, but the function is used incorrectly in the example shown.

    Later, I found an article that explains how to rewind the input stream—stdin—using a different function rather than fflush: rewind(stdin) Clears Keyboard Buffer

    Before I discovered the previous two articles posted above, I came across this article. Not much of an article, but this sentence caught my attention:
    The function call fflush(stdin) may be used to clear the input stream, stdin.
    My guess is programmers believe they can flush an input stream with fflush(), but in reality is undefined behavior. Though, some library references still use it incorrectly. Sometimes I ponder how flushing an input stream is really going to help in any program. If anything, the output stream should be flushed. Just my two cents.


    Regards,

    Stack Overflow
    Segmentation Fault: I am an error in which a running program attempts to access memory not allocated to it and core dumps with a segmentation violation error. This is often caused by improper usage of pointers, attempts to access a non-existent or read-only physical memory address, re-use of memory if freed within the same scope, de-referencing a null pointer, or (in C) inadvertently using a non-pointer variable as a pointer.

  7. #7
    Registered User
    Join Date
    Aug 2003
    Posts
    470
    This has to be a joke.
    http://en.wikipedia.org/wiki/Microsoft#Business_culture
    All the sudden microsoft started to worry about other browsers?!? They don't even care about theirs.
    http://en.wikipedia.org/wiki/http:/...owsers#Security
    I don't know Java Script, but one part of their code looks to be checking for Mozilla and IE versions greater than 3. Seems to be a simple ommision and the copyright on the top of the file isn't even Microsoft's. I've probably used Opera on msdn before Opera fixed(or accounted for)the problem. Just some coloring overlap when viewing msdn, I think.

    Wikipedia, too, is bit biased. For instance, Wikipedia says "Ease of use: Microsoft has been accused of allowing the user interface of its products to become inconsistent and overly complicated, requiring interactive "wizards" to function as an extra layer between the user and the interface. This violates the anti-modality principles of early user interface design (the principle that the user should be forced to do one particular thing as little as possible)." At least according to Raskin(I don't have the book on hand so this is what I remember) an application is modal if it's divided into modes. I don't see how this relates to "do one particular thing as little as possible".

    All the sudden microsoft started to worry about other browsers?!? They don't even care about theirs. http://en.wikipedia.org/wiki/http:/...owsers#Security
    OK, I agree with you that Opera is over all a better browser. But what I disagree with you, and this is just my impression of what your saying, is that Microsoft is some "Evil" cooperation out there to get people.

    I like Chris Torek's "cost-benefit analysis" description. And I'd say the issue is with the programmer.
    Dave_Sinkula, user input and output are usually non-standard in most applications. Even the ones that use a console interface still like to have colored backgrounds and getch like key input. So the key, I think, is separating out the non-portable stuff from the portable stuff. For instance, if someone's using "write" and "read" on a section of code that's supposed to be portable, then there's a problem, really one depending on how portable the code is supposed to be. But someone casually reading code with fflush(stdin) will think the code portable when it's not; and when problems do arise they're be hard pressed to figure out. The cost benefit is tilted on not using it. On the other had, the unix file functions can be non-portable, too, but at least they're documented non-standard in the man pages and the the worst that will happen, I think, is that the compiler won't have the right header files.

    My guess is programmers believe they can flush an input stream with fflush(), but in reality is undefined behavior. Though, some library references still use it incorrectly. Sometimes I ponder how flushing an input stream is really going to help in any program. If anything, the output stream should be flushed. Just my two cents.
    Stack Overflow, I'm under the impression that Microsoft defines what fflush(stdin) wil do. What I mean is, it's not quite undefined by MS, in that two or three different calls to fflush(stdin) will result in inconsistent behavior. But to the standard, however, it's undefined, so I'm led to believe a compiler could have each call to fflush(stdin) result in different behavior, I think.

  8. #8
    Registered User
    Join Date
    Jun 2004
    Posts
    722
    Quote Originally Posted by okinrus
    I've probably used Opera on msdn before Opera fixed(or accounted for)the problem. Just some coloring overlap when viewing msdn, I think.
    If you identify Opera as Opera, you get no toolbats nor left menu. If you identify it as IE you get everything working very well.
    Quote Originally Posted by okinrus
    OK, I agree with you that Opera is over all a better browser. But what I disagree with you, and this is just my impression of what your saying, is that Microsoft is some "Evil" cooperation out there to get people.
    I wasn't comparing IE with Opera. Microsoft has neglected for years, IE's security and standards compliance, because IE retains most of the browsers market share.

Popular pages Recent additions subscribe to a feed

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