Quote:Original post by Enigma I still prefer Scott Meyer's* Templatized-Null-On-Crack™.
Or you could just get GCC an save yourself some typing.. Well, it won't work for overloaded argument types but that's exceedingly rare in practice and you'll at least get a warning.
NULL's definition is a convienience, but according to specification, 0 is defined as "no target", and according to hardware, might not be physically a 0. For instance, if you have a machine where 0xffffffff is the no target for pointers, then ptr=0; will, according to C specification, assign 0xffffffff to ptr.
But yeah, NULL is usually 0 or (void*)0. I just use 0 personally.
In C++ you are supposed to use 0 (an implicit cast from 0 to any pointer type is required by the standard, this is different than C and is a special case just for 0).
In C you are supposed to use NULL because, as mentioned, it explicitly cast 0 to the correct pointer type. Theoretically it doesn’t have to be the integer value 0 either.
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Quote:Original post by FlyingDemon If NULL is defined as 0 would it be wrong to set pointers to 0 instead of NULL?
Don't go there man, just don't go there! (Damn I'm too late[smile]) There are plenty of existing topics that discuss the issue, if you'd like to search the site.
i dont think it means anything but off hand setting something to 0 is in fact setting it to nothing unless it was an int, setting to NULl actually to me sounds like u are setting it to nothing . . i dont know