+ 2
malloc casting in C vs C++
Why we need to cast malloc in C++ but it is not a good practice to cast it in C? https://code.sololearn.com/c0l49BxcipYK/?ref=app
2 odpowiedzi
+ 4
The newer C++ is pretty strict in types checking. It essentially says that if you need a pointer to char, then you have to provide a memory location that indeed holds characters and nothing else.
In C, the compilers are (or were) generally liberal. The onus of providing correct types is on the developer alone. This caused problems. So to eliminate it, strict type checking was recommended.
As a side note, you can use void * as it'll generate a warning alone. Read more about compiler flags, it's helpful :-)
+ 4
Thank you!