Returning a de-referenced NULL

Started by
31 comments, last by Dmytry 18 years, 4 months ago
This is definitely a place for an exception. If the compiler will complain about a missing return despite an unconditional 'throw' immediately preceeding it, I'd suggest returning a default-constructed object (or, if the default constructor doesn't do anything, a bounding box with the coordinates initialized to +/- infinity or NaN) for those truly odd "just in case" situations.
"Walk not the trodden path, for it has borne it's burden." -John, Flying Monk
Advertisement
Yes, that's how you would create a null reference. It most likely doesn't crash in that function because the dereference is cancelled out by the fact that you want to return a reference, which basically being a pointer, does the opposite of dereferencing (i.e. getting the address of it).

It's still an abomination though.
"In order to understand recursion, you must first understand recursion."
My website dedicated to sorting algorithms
Considering that this is still verion 0.1 and is probably still in production... looks like the author has gone to great lengths in avoiding people using this function!

Also, the int 3 is forcing people to use x86 machines for debugging! Whatever happened to ASSERT?

Everyone to his own...
to get the benefits of int 3 you could (should) use the __debugbreak() intrinsic (at least on ms compilers). works on 32 and 64 bit, native and managed.
Quote:Original post by Aryabhatta
Considering that this is still verion 0.1 and is probably still in production...

...one should stay away from versions 0.2 through 2.4?

Bad programmers write bad code. That's some bad code. There's bound to be more.
Quote:Original post by Oluseyi
Quote:Original post by Aryabhatta
Considering that this is still verion 0.1 and is probably still in production...

...one should stay away from versions 0.2 through 2.4?

Bad programmers write bad code. That's some bad code. There's bound to be more.


LOL :-)
I never said that the code was good (how in the world did you deduce that?). Anyway, if the author knows what he is doing and is probably going to change the code soon, you can say that the code is bad, but not that the author is a bad programmer.
There's no reason to do something like that in the first place. If you're going to poison a function like that then why bother to even define it? Just leave out the definition and you can detect at link time that the function is unimplemented and not have to deal with the landmine at runtime.
Quote:Original post by SiCrane
There's no reason to do something like that in the first place. If you're going to poison a function like that then why bother to even define it? Just leave out the definition and you can detect at link time that the function is unimplemented and not have to deal with the landmine at runtime.


Unless we know the reason why the author put that in, we cannot claim that (s)he is a bad programmer. I don't think it is fair to the author to jump to such a conclusion based on one such snippet.
Quote:Original post by Aryabhatta
Quote:Original post by SiCrane
There's no reason to do something like that in the first place. If you're going to poison a function like that then why bother to even define it? Just leave out the definition and you can detect at link time that the function is unimplemented and not have to deal with the landmine at runtime.


Unless we know the reason why the author put that in, we cannot claim that (s)he is a bad programmer.


Sure we can - or at least that they were. Stubbing out a function with undefined behavior like that is just silly.
Heres my question:

The function still needs a return value to compile, even if you throw an exception, doesn't it. So the line of code with undefined behavior still needs to be there to make it compile, right? Or am I missing something...


Edit: Removed an assumption that was not true

Check out my new game Smash and Dash at:

http://www.smashanddashgame.com/

This topic is closed to new replies.

Advertisement