[PATCH 08/16] libiberty.h: Provide a CLEAR_VAR macro
DJ Delorie
dj@redhat.com
Mon Jun 1 21:47:00 GMT 2015
> +/* Fill an lvalue with zero bits. */
> +#define CLEAR_VAR(S) \
> + do { memset (&(S), 0, sizeof (S)); } while (0)
Hmmm... I don't see the point in this. The macro is almost as long as
a bare memset() would be, and replaces a well-known function with
something unknown outside this project. It neither hides a bug in an
OS nor provides a common way to handle a difficult task across
platforms.
You also do NOT want to use memset to zero out a C++ structure that
contains more than just "plain old data" - you could easily corrupt
the structure's hidden data.
Also, pedantically speaking, "all bits zero" is not guaranteed to be
the same as float 0.0, double 0.0, or pointer (void *)0.
More information about the Binutils
mailing list