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

You don't have to cast void * back and forth to anything.

   void *p = /* ... */;
   char *q = p;
Despite what the C++ weenies will say this is valid C! Please do not commit this cardinal sin:

   char *p = (char*)malloc(n);
No no no! No need to cast that! Please just write:

   char *p = malloc(n);
And if somebody tells you that won't compile without an explicit cast, please kindly remind them what language you are writing.

[Actually I agree with you that C++ templates are really nice, chiefly for the reason that they allow you to avoid function pointers. In C++ you can pass your "callback" to a template and it gets inlined right with the body of the function.]



Very true. It's my biggest annoyance with Visual Studio when I write straight C code that the intellisense error checker moans about this.

The compiler is of course perfectly happy when it's running in C mode. But then I'm still upset about <stdbool.h> it should get off my damn lawn.




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

Search: