K
Keith Thompson
E. Robert Tisdale said:Nonsense!
No, it's not nonsense, as we've repeatedly explained at length.
Lots of people who post here have good rerasons
to cast the pointer returned by the malloc(size_t).
You claim to have a good reason, with no real justification that I've
seen. P.J. Plauger apparently does have a good reason; he needs to
write code that his customers can compile either as C or as C++. I
haven't seen anyone else make a coherent argument in favor of casting
the result of malloc().
[...]
Write:
char* p = (char*)malloc(n*sizeof(char*));
and both C and C++ compilers will accept your code.
Write
char *p = malloc(n);
or
some_type *p = malloc(n * sizeof *p);
and use a C compiler. Or use a "new" operator and use a C++ compiler.