Issue
Is there anything in the C Standard preventing me of doing the following?
// main.c
#define DECORATE(x) ***x***
#include "call_macro.h"
this is the text I want decorated)
// call_macro.h
DECORATE(
When running it though gcc -E main.c
, I expected to get
*** this is the text I want decorated***
Instead, it complained about macro_call.h:2: error: unterminated argument list invoking macro "DECORATE"
, but I can't actually find any prohibition of it in the standard.
Thoughts?
Solution
5.1.1.2 Translation phases
(1.4) Preprocessing directives are executed, macro invocations are expanded, and_Pragma
unary operator expressions are executed... A#include
preprocessing directive causes the named header or source file to be processed from phase 1 through phase 4, recursively. All preprocessing directives are then deleted.
I believe this says that each included header is preprocessed separately, before being "merged" into the overall translation unit. It is at this point that an incomplete function-like macro invocation would be ill-formed:
6.10.3/4 ... There shall exist a
)
preprocessing token that terminates the invocation.
Answered By - Igor Tandetnik