Difference between revisions of "CheckingNull"

From Nsnam
Jump to: navigation, search
(No difference)

Revision as of 20:50, 23 June 2008

In general, when setting or checking a pointer to be a null value, you should instead explicitly use 0 rather than NULL. For example, you should use:

  if (ptr == 0) {
    // code failed, whine to listserv
  }

As opposed to the commonly used:

  if (ptr == NULL) {
    // code failed, whine to listserv but say you used 0
  }

In any event, you should definitely not use:

  if (!ptr) {
    // you're fired!
  }

There is some discussion about this issue here. In general, NULL is not as crisply defined or its use as straightforwardly intuitive as using 0. The implicit check is also generally avoided in NS3 for reasons of code clarity.