This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC 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]

Passing empty "tag" structs


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?

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);

That would let you use tags for a variety of safe programming techniques with absolutely zero overhead.

mvh.,

David


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