Skip to main content


I have a complaint about #Plan9 #C.

I don't like that a literal 0 is accepted as a null pointer. I just spent an embarrassingly long time tracking down a segfault because in an attempt to zero out a buffer, I accidentally used memcpy(&buf, 0, sizeof(buf)) instead of memset(&buf, 0, sizeof(buf)).

The compiler should've been able to catch this.

#c #plan9
This was a specific design decision, not due to lack of ability to implement a warning around. You can use acid(1) on the broken proc to get the exact source line that the code crashed on. Which can help narrow down the cause of a segfault.
@moody Yeah, I haven't figured out acid, yet. I'm curious what the arguments in favour of that decision were though.
It is standard C as far as I know. gcc with -Wall (at least on my machine) does not generate a warning for any integer constant to pointer conversion. The plan 9 compilers will generate an error for all integer constants to pointer conversions other than zero. So we are actually more strict than UNIX compilers about this! It is legal to define NULL on UNIX as just 0 (without the cast). So my guess was that this exception was kept for compatibility with UNIX code.
@moody then I suppose my complaint is with C itself. ;)
There is a reason why go removed all implicit casts.

This website uses cookies. If you continue browsing this website, you agree to the usage of cookies.