This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [PATCH 08/16] libiberty.h: Provide a CLEAR_VAR macro
- From: DJ Delorie <dj at redhat dot com>
- To: David Malcolm <dmalcolm at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org, binutils at sourceware dot org
- Date: Mon, 1 Jun 2015 17:47:00 -0400
- Subject: Re: [PATCH 08/16] libiberty.h: Provide a CLEAR_VAR macro
- Authentication-results: sourceware.org; auth=none
- References: <1433192664-50156-1-git-send-email-dmalcolm at redhat dot com> <1433192664-50156-9-git-send-email-dmalcolm at redhat dot com>
> +/* 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.