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

Reply via email to