Optimzed vs. readable code

Ian Lance Taylor ian@airs.com
Thu Dec 1 17:16:00 GMT 2005


Gabriel Dos Reis <gdr@integrable-solutions.net> writes:

>   http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2004/n1614.pdf

Interesting, but it doesn't seem to describe:

#scope
#define COMB ::
#define combine(a,b) a::b
#export combine
#endscope

#define COMB quux
int x = combine(foo,bar);

Has this issue been discussed anywhere?

How should it work?  In the above example, it seems clear that combine
should be rewritten internally to refer to a renamed, private, version
of COMB.

But that would prohibit a capability which currently exists, to have a
macro refer another macro and to have the code #undef and #define that
other macro.  For example:

#scope
#define EFUNC standard_error
#define CHECK(x) ((x) || EFUNC (__FILE__, __LINE__))
#export CHECK
#endscope

CHECK(foo);
#undef EFUNC
#define EFUNC my_error
CHECK(bar);

We could argue that this will only work as desired if we #export
EFUNC.  Then we would have to make sure to only rewrite CHECK to use a
private version of EFUNC if EFUNC is not #exported.  That's slightly
nasty since at the time of the #define of CHECK we don't know whether
or not EFUNC is exported.

It gets nastier if we have nested scopes.  We might #export both CHECK
and EFUNC to the enclosing scope, but then only #export CHECK to the
next enclosing scope.  That would imply that we have to rewrite CHECK
again when the enclosing scope closes.

Generally a cool idea, though.

Ian



More information about the Libstdc++ mailing list