Kenneth Brody said:
here.
It's considered bad practice, as it can hide a missing #include for
the malloc-and-friends prototypes. Without those prototypes, all
bets are off as to what happens when the compiler takes what it
thinks is an int return and casts it into your pointer.
Yeah, yeah, yeah, but interestingly apropos to the original question,
if you should for some reason decide to use malloc() instead of new()
in a C++ program, you MUST cast the return value. If you don't,
you'll get a compiler error! (Which happens for many of the "little"
differences between C types, standard libraries, and semantics
when used in a C++ program.)
And of course, it is exactly this required explicit typing of return
values in C++ that precludes all the "horrible" problems (which
only occur if you make another ACTUAL mistake) of NOT casting
the value in C!
But like the use of extern "C", this is not just off-topic, but beyond
the scope of knowledge of many of the frequent posters here, as
evidenced by their struggle in this thread to come to grips with
some simple realities of real-world programming as it is and was
performed at any time in the last 15 years or so...