lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


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
> > [1] that advice against casting that pointer (as opposed as what you
> > should do in C++), as Sean said.
> 
> Let us see [1]:
> 
> * "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
> errors.
> 
> * "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 ... )