https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89665
Bug ID: 89665 Summary: inconsistent macro expansion Product: gcc Version: 7.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: preprocessor Assignee: unassigned at gcc dot gnu.org Reporter: gciofono at gmail dot com Target Milestone: --- Created attachment 45941 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=45941&action=edit hellomacro.c shows the inconsistent macro expansion of gcc. The preprocessing of the macros follows a lazy-expansion algorithm that is not entirely satisfying, nor exactly matching the description of the gcc guide, paragraph 3.10.6 Argument Prescan. I find that an argument should be expanded each time it is used, or (suboptimal) each time it is declared, but the gcc preprocessor does none. My full gcc version with Ubuntu 18.04 is: gcc (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0 please compile with (includes only stdio.h but it is unavoidable to see the output): gcc -v -save-temps -o hm hellomacro.c the commented result of execution is: $ ./hm 0-1-2-3-4 << 5 times expansion of __COUNTER__, as expected x << INCONSISTENCY: no expansion to __COUNTER__, because not used direcly 5-5-5-5-5 << inconsistency: 1 expansion of counter. 5 times would have been better x << inconsistency: 1 expansion of counter, because of it indirect use, but finally discarded like two lines above 7-7-7-7-7 << output of the current counter (6 is skipped).