Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

IMO you should assert it's not null. There should never be a circumstance where you pass a null pointer to a function.


ISO C allows:

  free(NULL); // convenient no-op, does nothing

  fflush(NULL); // flush all streams; done implicitly on normal exit

  time(NULL); // don't store time_t into a location, just return it

  strtol(text, NULL, 10);  // not interested in pointer to first garbage char

  setbuf(stream, NULL);  // allocate a buffer for stream

  realloc(NULL, size); // behave like malloc(size)
and others. More examples in POSIX and other APIs:

  sigprocmask(SIG_UNBLOCK, these_sigs, NULL); // not interested in previous signal mask

  CreateEventA(NULL, FALSE, FALSE, NULL); // no security attributes, no name
Reality just ran over your opinion, oops!


I'm sorry. Are you claiming the people who designed those functions made good choices? They altered the behavior of the function considerably for a single input value that is more likely to be a bug than not.


Yes. I will probably continue to make similar choices of the future.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: