On 07/09/2018 10:10, Jonathan Wakely wrote:
On Fri, 7 Sep 2018 at 08:06, David Brown wrote:

In C++ programming, it is sometimes helpful to have empty structs acting
as tags.  An example is "struct nothrow_t {}".

When parameters of these types - such as "nothrow", are passed to
functions the compiler passes them as a value 0.  Since the type cannot
hold any kind of value, surely it could be passed without any value at
all being placed in the corresponding parameter register or stack slot?
Or do the rules of C++ require a value here?

The ABI dictates it, and in GCC 8 it was fixed, see
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60336

Going one step further, if a function takes empty tag parameters such as:

         foo(tag1_t, tag2_t, int x);

the first two parameters take up valuable register (or stack) slots for
no useful information.  Could this function be mangled to be, in effect:

         foo__tag1_t__tag2_t(int x);

No, the ABI also dictates how to mangle functions.


Thanks for the information here. The bug you linked has more detail than I can follow, but after some more testing it looks like gcc 8 handles empty tags exactly as I would like it. For earlier versions (I work with embedded systems - we rarely get the latest and greatest compiler versions) of gcc I can just make wrapper functions to eliminate the overhead of the tags.

Thank you for continuing to make the compiler better!

mvh.,

David

Reply via email to