...how when some functions return 0, it was a success, yet when others return NULL, it's a failure?
...how when some functions return 0, it was a success, yet when others return NULL, it's a failure?
Originally Posted by The Jargon File
err, no?
Depends on exactly the functions you are talking about here. But null and 0 are two very distinct things. And even when used in a return value to denote failure, they still have a distinct semantics that is quite intentional.
Care to give an example of what functions you are talking about. Are we discussing C here, per chance?
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.
Originally Posted by The Jargon File
I'll give you a few minutes to think why's that...
Think of what the function is returning exactly and what is the use you make of what is returned.
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.
That's because strcmp() doesn't check to see whether the two strings match, it compares their lexical value. Considering you probably don't know what that means, you really should read the manual on strcmp().
As far as malloc() goes... what else could it possibly return on failure?
Also, I would disagree about NULL != 0. In C(++) they are quite the same thing, often times even semantically. Calling zero, null, only implies that the variable holding the value in question, is probably a pointer.
EDIT: Never mind..
*facepalm*Originally Posted by CommonTater
You should take your own advice...
C: What is NULL and how is it defined?
C++: Should I use NULL or 0?
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
>> Also, I would disagree about NULL != 0. In C(++) they are quite the same thing, often times even semantically.[/quote]
So, you are saying it's quite alright to write:
if (myClass == 0) do_something();
Maybe the word "semantics" has a different meaning to you and me. Coincidentally, this is an old, old, old, debate that I have no wish of starting with you. So if your answer to the above code is "that is perfectly alright", suit yourself.
>> Calling zero, null, only implies that the variable holding the value in question, is probably a pointer.
Ah!... I love the smell of uncertainty in the strongly-typed morning.
Last edited by Mario F.; 07-25-2011 at 10:34 PM.
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.
Maybe, maybe not. It depends on what is myClass. If it is a class name, then that would result in a syntax error, so the answer to your question becomes blatantly obvious.Originally Posted by Mario F.
nullptr FTW!Originally Posted by Mario F.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
It's not that either. It is the value 0, cast to a void*. It doesn't point to 0; it doesn't point anywhere (that is, after all, the point of NULL).
(Edit to add: If you want to say that, in the case of a pointer, "having the value of" and "pointing to" are the same thing (i.e.
where x has the value 0x100 and points to 0x100), that would be fine; however, that's not where we started this sidetrack....)Code:void *x = 0x100;
Last edited by tabstop; 07-26-2011 at 06:53 AM.