Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Sorry, Unlink, but never define something yourself that's defined by the standard. You'll be safe in 99.999% of all cases with your [tt]#define NULL[/tt], and absolutely stumped when the one-in-a-million case pops up where some part of the library depends on NULL being something different...
Every good solution is obvious once you've found it.
i know that solar, i just extract this piece of code from minix, so he knows how it's defined.
he shouldn't depend on this as a default value of NULL while it is part of stddef.h
is ok for C it is not 100% correct in c++ because c++ lacks the rule that void pointers are implicitly convertable to any pointer type. If NULL were defined this way in c++ code, there would no legal way to assign NULL to a function pointer since data pointers are not allowed to be converted to function pointers in c++.
So if you intend to define NULL for your c++ code, the best bet is:
zloba wrote:
are there any reasons to use NULL instead of just 0 ?
what special semantics does NULL provide, and where does it matter?
The point is that NULL is used throughout the C standard library, and that its actual value is implementation defined (by the library implementation). When a function is advertised to return NULL (like [tt]fopen()[/tt]), it will return whatever the lib defines as NULL, which might be 0 or (void *) 0 or whatever.
That means you cannot mix your own definitions of NULL with those of some existing library. And even if you write your own library, it would be bad style to define NULL in one place and not using that definition consistently yourself.
Every good solution is obvious once you've found it.