cppmagic: Allow multiple and deferred evaluation
authorDavid Gibson <david@gibson.dropbear.id.au>
Tue, 26 Jan 2016 10:32:07 +0000 (21:32 +1100)
committerDavid Gibson <david@gibson.dropbear.id.au>
Wed, 3 Feb 2016 22:44:13 +0000 (09:44 +1100)
commit7ddee86d9ac424dbec04583e37e9584375bd6d74
treee245f1eec28623616b67f32d21aee559dc7c9c41
parent395a2f841356e5bba4935a24093d30d67c1f3ef5
cppmagic: Allow multiple and deferred evaluation

Recursion (and therefore iteration) in cpp is difficult, since the
preprocessor explicitly looks for and inhibits recursion.

But, it's possible to trick it, up to a point.  CPPMAGIC_DEFER1() and
CPPMAGIC_DEFER2() can "hide" a macro, preventing it from being expanded
and being noticed as recursion.

Along with that we need to cause extra expansion passes to be executed.
There has to be a finite limit here - true recursion is impossible - but
that number can be made very large pretty easily.  CPPMAGIC_EVAL() multiply
expands its argument(s) - up to 1024 times.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
ccan/cppmagic/cppmagic.h
ccan/cppmagic/test/run.c