Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #146704

Preprocessor and "empty" substitutions

From Andrey Tarasevich <andreytarasevich@hotmail.com>
Newsgroups comp.lang.c
Subject Preprocessor and "empty" substitutions
Date 2019-10-07 12:03 -0700
Organization A noiseless patient Spider
Message-ID <qng257$6ts$1@dont-email.me> (permalink)

Show all headers | View raw


Hello

Consider the following two simple tests

   #define OUTPUT(x) printf("%d\n", x)

   #define EMPTY
   #define TEST(x) OUTPUT EMPTY (x)

   int main(int argc, char **argv)
   {
     int i = 42;
     TEST(i);
   }

   http://coliru.stacked-crooked.com/a/fe355c96201c9fb1

and

   #define OUTPUT(x) printf("%d\n", x)

   #define TEST(x, y) OUTPUT y (x)

   int main(int argc, char **argv)
   {
     int i = 42;
     TEST(i, );
   }

   http://coliru.stacked-crooked.com/a/537978e2b5888de3

The idea is to inject something "empty" into the replacement list of 
macro 'TEST' between 'OUTPUT' and '(x)'. In the first case that 
"emptiness" arrives through an independently-defined object-like macro 
'EMPTY'. In the second case it is brought in by a macro parameter 'y'.

These two cases behave differently. In the first case the further rescan 
does not recognize 'OUTPUT(x)' invocation in 'TEST's replacement list. 
In the second case the 'OUTPUT(x)' invocation is recognized.

Apparently, in the first case the macro 'EMPTY' is not that "empty": it 
leaves something behind after replacement (an empty pp-token?). Whatever 
it leaves behind apparently prevents the preprocessor from seeing tokens 
'OUTPUT' and '(' as immediately adjacent. The invocation of 
function-like macro 'OUTPUT(x)' is not recognized. (Is this analysis 
correct?)

In the second case parameter 'y' is apparently truly "empty" - it 
disappears without a trace, turning 'OUTPUT' and '(' into immediate 
neighbors. Subsequent rescan sees 'OUTPUT(x)' invocation.

So, what exactly happens in the first case? What does 'EMPTY' leave 
behind after substitution? Which specific wording the the standard says 
that empty parameter values are truly "empty", while empty macros are not?

-- 
Best regards,
Andrey Tarasevich

Back to comp.lang.c | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

Preprocessor and "empty" substitutions Andrey Tarasevich <andreytarasevich@hotmail.com> - 2019-10-07 12:03 -0700
  Re: Preprocessor and "empty" substitutions Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-10-07 21:05 +0100
    Re: Preprocessor and "empty" substitutions Andrey Tarasevich <andreytarasevich@hotmail.com> - 2019-10-07 15:16 -0700
      Re: Preprocessor and "empty" substitutions Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-10-08 01:41 +0100
        Re: Preprocessor and "empty" substitutions Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-10-09 01:58 +0100
        Re: Preprocessor and "empty" substitutions Andrey Tarasevich <andreytarasevich@hotmail.com> - 2019-10-08 11:41 -0700
          Re: Preprocessor and "empty" substitutions Tim Rentsch <tr.17687@z991.linuxsc.com> - 2019-10-09 06:34 -0700

csiph-web