Thread: "Bad Bit"

  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    21

    "Bad Bit"

    I'm currently experimenting around with how to break things within the bits in a stream. As far as I know there are 3 "naughty bits". There is a "fail bit", an "end of file bit" and a "bad bit". As far as I can decipher the "bad bit" is due to a hardware failure. I have tried EVERYTHING that I can think of to try and trip the "bad bit" and I can't seem to accomplish it. Does anybody have any insight?

  2. #2
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    The badbit is set after a system failure affecting the stream. It's not easy to deliberatly provoke it. It's usually not possible to recover from it, so this is an error that should originate a program failure and termination.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Write your custom stream insertion/extraction operator and throw an exception from that:
    Code:
    #include <iostream>
    #include <stdexcept>
    
    class dummy {};
    
    ostream & operator << (ostream &, const dummy &)
    {
      throw std::runtime_error("gotcha")<
    }
    
    int main()
    {
      try {
        std::cout << dummy();
      } catch(std::runtime_error &) {
      }
      bool b = std::cout.fail();
      std::cout.clear();
      std::cout << "Failbit: " << b << "\n";
    }
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. fopen returning "Bad File Pointer"
    By jprukop in forum C Programming
    Replies: 4
    Last Post: 04-17-2009, 03:01 PM