[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: [patch][c++] fix "invalid conversion from ‘void*’ to ‘char*’"
- From: "Christian N." <cn00@...>
- Date: Tue, 28 Jun 2016 21:38:54 +0200
On 2016-06-28 21:32 +0200, Sean Conner wrote:
It was thus said that the Great Roberto Ierusalimschy once stated:
What I really meant was that with that macro you could perform the
cast on the pointer returned from malloc only when compiling as C++,
and avoid the cast in C, in order to "conform" to C best practices
 that advice against casting that pointer (as opposed as what you
should do in C++), as Sean said.
Let us see :
* "It is unnecessary" - so are comments, identation, etc.
* "It can hide an error, if you forgot to include <stdlib.h>." - This
could be a valid argument 20 years ago (K&R C). If you do not use
something like -Wstrict-prototypes and -Wmissing-prototypes, something
is very wrong, as every single function call in your program could hide
* "It adds clutter to the code" - A macro would add even more "clutter".
* "It makes you repeat yourself" - So does a macro.
So if you are adding the casts because C++ requires them, then you should
also remove all NULLs since C++ practically rejects those.
-spc (and to further compound the issue, you should therefore define
nullptr to be NULL when compiling with a C compiler, because you
know ... C is a second class citizen ... )
Edge cases with overload resolution aside (which Lua, being written in
the C subset of C++, is not affected from), there is no problem with
using NULL in C++. In fact, before C++11 introduced nullptr, it was
common practice, so I wouldn't even say that NULL is "C style".