Comment

Comment by cjensen

So I immediately checked my favorite language gotcha, the macro NULL. The text is entirely wrong. The macro NULL is harmful in both C and C++. It is not "stylistic" AT ALL.

Here's the problem with the macro: the macro NULL can be either 0 or can be (void * ) 0. The issue is that the former can be accidentally interpreted as an integer depending on context.

In both C and C++, this manifests when you pass NULL to a varargs function. Instead of passing in a null pointer, the compiler may instead pass in an integer zero. If pointers and ints have different sizes, hilarity ensues. If the null pointer does not have the same bit representation as int zero, hilarity ensues.

In C++, this happens even more commonly. If there is an operator overload and you pass in NULL, then if NULL is 0 it will chose the int overload, if NULL is (void * ) 0 it will chose a pointer overload.

Never use NULL. Ever.

parent cjensen 8 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton