DEV Community

Discussion on: Single Linked List Using C

Collapse
 
ac000 profile image
Andrew Clayton

In C, you shouldn't cast the return value from malloc(3) et al.

Collapse
 
0orion0 profile image
Orion

Why ?

Collapse
 
ac000 profile image
Andrew Clayton

In C (and we're talking about C and not C++)

1) It's superfluous.
2) Can hide bugs depending upon architecture/compiler etc, where if you don't

#include <stdlib.h>
Enter fullscreen mode Exit fullscreen mode

the return type of malloc may be assumed to be int which may mean you're using a truncated address and that won't end well...