It's NOT as obvious what you are doing when you use NULL. C++ doesn't define a NULL pointer as a pointer with the value NULL, NULL means nothing directly in C++ -- a "NULL pointer" is defined as a pointer with the value 0. Using NULL doesn't make anything more clear, it just opens up the question "what is NULL defined as here." If someone doesn't understand that when you set a pointer's value to 0 that it's a NULL pointer, then they don't understand the language.Originally posted by Magos
I prefer to use NULL since it's more obvious what you're doing, making a pointer into a NULL pointer. By setting it to 0 manually, you can misread and think that you set what it's pointing at to 0.
You don't use magic numbers when there is a possibility that you would at some point in time want to change the value. That is not the case with 0. Setting a pointers value to 0 is a direct part of the language -- defining NULL to 0 doesn't make your code any better because you'd never ever want to change NULL to another value when using it for a NULL pointer, and if you did, then you'd only open yourself up to errors. The reason you'd use a constant (macros, particularly in places like this, are generally poor practice) are when you have a number that you want to be able to easily change when you compile. You would never want to change NULL to a different value, and if you did, then your code wouldn't compile because the only valid integer you can assign as a value to a pointer directly is 0. NULL just adds the possible question "what is NULL defined as here." That is silly. A NULL pointer has a value 0, period. You'd never want to change that. Unless NULL becomes a direct part of the language, then it's not as safe as using 0, and despite what you claim, using 0 is more clear to someone who knows the language because that is how the language defines a NULL pointer.Originally posted by Magos
Get rid of the magic numbers and use definitions instead, it makes the code easier to read and understand.