Expand a macro in a macro
Citing C99 draft 6.10.3.4
Rescanning and further replacement §2 (emphasis mine):
If the name of the macro being replaced is found during this scan of the replacement list (not including the rest of the source file’s preprocessing tokens), it is not replaced. Furthermore, if any nested replacements encounter the name of the macro being replaced, it is not replaced. These nonreplaced macro name preprocessing tokens are no longer available for further replacement even if they are later(re)examined in contexts in which that macro name preprocessing token would otherwise have been replaced.
From folowing macro-definitions:
#define spec(_H_) spec_##_H_
#define spec_namespace(_H_) spec_namespace_##_H_
#define spec_namespace_unmanaged spec(section(".unmanaged"))
It's clear that spec
macro is evaluated twice, so no futher replacement is done, let's take it step-by-step:
spec(namespace(unmanaged)) int x; → spec_namespace(unmanaged) int x;
spec_namespace(unmanaged) int x; → spec_namespace_unmanaged int x;
spec_namespace_unmanaged int x; → spec(section(".unmanaged")) int x;
What you can do about it is to modify your last macro-defintion into following form:
#define spec_namespace_unmanaged attribute ((namespace (".unmanaged")))
or maybe simplify it as:
#define spec(_H_) spec_##_H_
#define spec_section(_S_) attribute ((section (_S_)))
#define spec_namespace(_N_) attribute ((namespace (_N_)))
with:
spec(namespace(".unmanaged")) int x;