• (cs) in reply to Rich
    Rich:
    captcha: xevious i hated that game

    You heathen! ;-)

  • Miral (unregistered) in reply to Andrew
    Andrew:
    In any case, the system has crashed when stderr stream is not available.
    Untrue. The application could have previously closed stderr, or it could have been started up without stderr being open (daemons are frequently run this way).
  • Miral (unregistered) in reply to EvanED
    EvanED:
    In fact, I'm not even sure if just checking errno is valid. I'm under the impression that if a function succeeds what it does to errno is undefined, so you can't rely on it being a specific value when it comes out. It could set errno when it succeeds in other words.

    Ignoring practical concerns about if this would ever happen in real code (I'm an academic ;-)), am I right about this? It's been a while.

    Yes, you are exactly correct. errno is unspecified on success -- it could be left alone, or it could be set to some random error code from some internal operation you don't know about.

  • (cs) in reply to snoofle
    So this is broken-register syndrome? If it fails the first time, do it a few more times to make sure it really takes?
    Looking through the Jargon File, Wikipedia and Google, it seems that if this terminology was ever used at large on the internet, it has disappeared entirely.
  • Anonymous commie (unregistered)

    I'm pretty sure that the original coder had kids, and that he/she had learned that it is usually not enough to tell them once. But if you have to tell then more than five times then you can: (a) let them have it their way ("no dinner tonight, then") (b) do it yourself, or (c) put up a fight. I also think that okThatsItYouAreGrounded() was not implemented at that time.

  • JGW (unregistered) in reply to CrystalMethod
    but my favourite is the belief that fprintf returns less than zero on error.

    Erm... That would be a correct belief.

    fprintf returns a negative number on failure AND sets errno, OR returns a positive number of bytes on success.

  • phs3 (unregistered) in reply to bstorer

    Although he did manage the official programmer misspelling of "occurred" (noun form: "occurance", for double misspelling points).

    ...phsiii

  • Sarcasm (unregistered) in reply to Matt
    CrystalMethod:
    This code is so naff, but my favourite is the belief that fprintf returns less than zero on error. fprintf returns the number of characters printed - on failure it sets errno.

    Since absolutely no one else has thought to correct you yet, let me jump in here and say that fprintf does, in fact, return a negative value on error.

  • mikko (unregistered) in reply to Onaka The Kaka

    That's right - form is so much more important than function! The code above is clean and easy to maintain ( so important to the majority of the WTF readers ) - should have at least one comment per line, though. How else can you justify spending so much time on worthless (Only in terms of function) code?

  • Worf (unregistered) in reply to snoofle
    snoofle:
    So this is broken-register syndrome? If it fails the first time, do it a few more times to make sure it really takes?

    No, it's just error-handling taken to the extreme. A lot of people don't realize that common everyday functions could fail, and then don't handle the error. Let's take a classic program:

    #include <stdio.h>
    
    int main()
    {
        printf("Hello, world!\n");
        return 0;
    }
    

    Can you spot where it may fail? (Yes, this program has a potential bug). (Hint - what's the prototype for printf(3)?).

    Now, whether or not the failure of a printf() or sprintf() function is something to worry about. If you actually wanted to code it properly and handle the cases where it failed, you'd add enough lines to turn this trivial program into something non-trivial. Such is the nature of robust programming.

  • (cs) in reply to bstorer
    bstorer:
    Oh, I see! It should have been:
    if (error)
      while (fprintf(stderr,"An error occured while writing to the file")<0);
    

    lol I love it

    That's much cleaner...

  • buy carisoprodol online bigraded extinguisher (unregistered) in reply to Quinnum
    Comment held for moderation.
  • purchase xanax (unregistered) in reply to Quinnum
    Comment held for moderation.
  • Pharme13 (unregistered) in reply to Quinnum

    Hello! decdcce interesting decdcce site! I'm really like it! Very, very decdcce good!

Leave a comment on “The Pyramid of Error”

Log In or post as a guest

Replying to comment #:

« Return to Article