You can call realloc() on a NULL pointer.
Printable View
I agree, of course you can. You have to be able to allocate pointer for NULL pointers, because of the simple concept of the "initialize your variables before you attempt to use them" mantra.
All a NULL pointer is is a variable whose value has been set to nothing. It's like initializing an int to 0 first.
Quzah.
6 in one, half a dozen in the other...
Both ways have advantages & disadvantages.
I would assume that if someone did find a discrepancy as you mentioned, they would fix it so the next reader doesn't have to go through the same head scratching motion. In 10 years I've never seen anyone try to assign NULL to a non-pointer. So I would say it's an extremely remote possibility.
That's right, which is why I think it boils down to personal choice. In C++ we can wait for nullptr, but I am afraid there is no good solution coming up for C.Quote:
Originally Posted by cpjust
I have done it myself when using some of those crazy programming interfaces with an excessive number of parameters, some of which are pointers while others are not. It is arguably a problem with the interface, but in such cases it does not matter whether the reader sees a NULL or a 0: he/she has to double check anyway.Quote:
Originally Posted by cpjust