This is the mail archive of the mailing list for the binutils project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [GOLD] Reduce size of class Symbol

On Thu, Aug 03, 2017 at 10:12:52PM -0700, Cary Coutant wrote:
> I like the goal, but the problem is that you're always accessing the
> plt_offset through the u_.from_object variant, no matter what variant
> is actually there. While you've been careful to make sure that the
> plt_offset field has the same offset in each variant, it's still both
> fragile and technically illegal.

This trick is allowed by the ISO C standard according to the
following, and I'm assuming is also valid for C++.  Re accessing via
the from_object variant, yes I guess it might be better style to
create a new struct union member just containing plt_offset.

>From ISO/IEC 9899:1999 section Structure and union members

5 One special guarantee is made in order to simplify the use of
  unions: if a union contains several structures that share a common
  initial sequence (see below), and if the union object currently
  contains one of these structures, it is permitted to inspect the
  common initial part of any of them anywhere that a declaration of
  the completed type of the union is visible. Two structures share a
  common initial sequence if corresponding members have compatible
  types (and, for bit-fields, the same widths) for a sequence of one
  or more initial members.


The following is a valid fragment:
	union {
		struct {
			int alltypes;
		} n;
		struct {
			int type;
			int intnode;
		} ni;
		struct {
			int type;
			double doublenode;
		} nf;
	} u; = 1; = 3.14;
	/* ... */
	if (u.n.alltypes == 1)
		if (sin( == 0.0)
		/* ... */

Alan Modra
Australia Development Lab, IBM

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]