It appears that CPP decides to stop expansion at some point.
Re-feeding the output to cpp iteratively peels macro levels.
#include <stdlib.h>
#include <stdio.h>
#define _(op, ...) op(__VA_ARGS__)
#define _if(expr, then, els) if (expr) { then; } else { els; }
#define progn(...) ({__VA_ARGS__;})
#define when(expr, ...) _(_if, expr, \
_(progn, ## __VA_ARGS__), )
#define unless(expr, ...) _(_if, !(expr), \
_(progn, ## __VA_ARGS__), )
#define warn(format, ...) _(fprintf, stderr, format "\n", ## __VA_ARGS__)
#define when_warn(expr, tail, format, ...) _(when, expr, \
_(warn, format, ## __VA_ARGS__),
\
tail)
#define exssert_with_epilogue_nexpr(expr, epilogue, format, ...) _(when_warn,
expr, _(exit, 1), format, ## __VA_ARGS__)
#define exssert_nexpr(expr, format, ...) _(exssert_with_epilogue_nexpr, expr,
(), format, ## __VA_ARGS__)
#define xmallocq(size) _(progn, \
void *gensym = malloc(size); \
_(exssert_nexpr, gensym == NULL, \
"malloc returned NULL at: %s:%s, line %d",
__FILE__, __FUNCTION__, __LINE__); gensym)
int main()
{
xmallocq(2000000000);
exit(0);
}
==>
int main()
{
({void *gensym = malloc(2000000000); _(exssert_with_epilogue_nexpr,
gensym == ((void *)0), (), "malloc returned NULL at: %s:%s, line %d","<stdin>",
__FUNCTION__, 88); gensym;});
exit(0);
}
--
Summary: Function macro nesting depth appears to be uncomfortably
limited.
Product: gcc
Version: 4.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: preprocessor
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: _deepfire at feelingofgreen dot ru
GCC build triplet: x86_64-linux-gnu
GCC host triplet: x86_64-linux-gnu
GCC target triplet: x86_64-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35301