Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Brobanx

How's this?

This topic is 5735 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts


  
#ifdef NDEBUG

  #define null 0

#else

  struct NullClass {
      inline NullClass() {}

      template <class T>
      operator T*() {
        return reinterpret_cast<T*>(0);
      }
  };

  #define null NullClass()

#endif
  
Too bad it doesn''t work under VC++6 though (might in 7, I can''t check that myself though). It''s a typesafe implementation of null. It can be converted to any type of pointer, but not anything else (like an int). This helps avoid those embarassing errors where you compare a dereferenced value to 0, rather than the pointer itself.

Share this post


Link to post
Share on other sites
Advertisement
never ever yet had those errors..

and i never make different code for debug and release. it just means _possibly_ the release gets a bug you never find in debugmode..

bether just code it directly..

both vc6 and vc7 can''t do templated member functions..


  
struct Null {
template<typename Type> operator Type*()() {
return reinterpret_cast<Type>(0);
}
};


its a neat idea..

but as i said. never had those bugs..

(never have pointers to ints, or something like that anyways.. only to types that wrap some stuff and are big..)

"take a look around" - limp bizkit
www.google.com

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!