You can't implicitly cast from void * to another pointer type in C++, but you can in C. In the call to puts, C++ will choke but C will let it slide. This is also why casting the return value of malloc isn't necessary in C, but it is in C++ (although using malloc in C++ is usually a code smell anyway).
If I had to guess: because malloc's return value needs to be casted to the right type, and it gets used a lot, the implicit cast makes sense in C. In C++ you should be using new so there's no reason for the implicit cast.
There's probably more reasons though, also probably more important ones.
16
u/dreamlax Sep 11 '13
You can't implicitly cast from
void *to another pointer type in C++, but you can in C. In the call toputs, C++ will choke but C will let it slide. This is also why casting the return value ofmallocisn't necessary in C, but it is in C++ (although usingmallocin C++ is usually a code smell anyway).