Don't use bfd_get_* macro to set bfd fields

Alan Modra amodra@gmail.com
Thu Sep 19 00:09:00 GMT 2019


On Wed, Sep 18, 2019 at 09:19:40AM -0600, Tom Tromey wrote:
> >>>>> "Alan" == Alan Modra <amodra@gmail.com> writes:
> 
> Alan> I've always thought it odd style to use a bfd_get macro on the left
> Alan> hand side of an assignment.  I didn't think it worth bothering to
> Alan> make a bfd_set variant for these as their use would be local to bfd.
> 
> One trick we use in gdb is to prevent these assignments by making the
> macro expand to an rvalue.  An example from gdb:
> 
> #define MSYMBOL_SIZE(msymbol)		((msymbol)->size + 0)

Yes, I know that trick.  Another is to turn the macros into inline
functions, which is nicer in some respects but puts more constraints
on where the functions can be defined.  Also, in converting a macro
like bfd_section_list_append you can't use NULL since that requires
NULL to be defined before the inclusion of bfd.h.

-- 
Alan Modra
Australia Development Lab, IBM



More information about the Binutils mailing list