Thread: don't be like this guy / monday lols

  1. #1
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    838

    don't be like this guy / monday lols

    Code:
         //lint -e{506}  Suppress the "constant boolean" msg
          if (NULL == &coefficients)
    that's all over this project i inherited. happy monday: at least you don't have to write unit tests for this dreck.

  2. #2
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    let me preface this by saying that checking the address of an object or a reference is a sign of very bad design.

    that being said, it is possible, under some circumstances, to have a reference that is essentially a dereferenced null pointer. in GTK+, for example, GUI event handler callbacks use a pointer to a function that receives a pointer to some data that you specify when you hook up the callback. if you are using GTK+ from a C++ program, you can tell it that a function that is declared as accepting a reference type parameter instead of a pointer should be used as the callback. since the function pointer is cast to a GCallback type when you hook it up, you can actually give it any function you want, and since most C++ implementations handle references behind the scenes as pointers, you can specify NULL for the data parameter, and when the callback gets called, the reference now refers to what amounts to a dereferenced null pointer. a former co-worker developed a lot of code this way, and it's likely the reason the program crashes so frequently. thankfully, that practice left with him, but its effects are still being felt.
    Last edited by Elkvis; 10-17-2011 at 10:59 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Asteroid almost hit the earth on Monday
    By VirtualAce in forum A Brief History of Cprogramming.com
    Replies: 19
    Last Post: 03-06-2009, 11:37 PM
  2. Last Monday's Game
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 10-30-2003, 06:55 PM