Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #146707
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Preprocessor and "empty" substitutions |
| Date | 2019-10-07 21:05 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <874l0kl3sm.fsf@bsb.me.uk> (permalink) |
| References | <qng257$6ts$1@dont-email.me> |
Andrey Tarasevich <andreytarasevich@hotmail.com> writes:
> 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);
> }
Here is the sequence (I'll put tokens in <> to make them stand out):
A function-like macro is detected because <TEST> is followed by <(>.
Arguments are collected. We get <i>. The token list
<OUTPUT> <EMPTY> <(> <x> <)>
has parameter <x> replaced by <i> to get:
<OUTPUT> <EMPTY> <(> <i> <)>
Now this list is scanned for further replacement, but the macro name
token <OUTPUT> is not followed by a <(> token so no function-like macro
invocation is seen.
<EMPTY> is seen as an object-like macro and is replaced by nothing, but
the scan does not go back to see if this makes any difference to the
decision not to recognise an invocation of a function-like macro. No
further tokens can be replaced and, importantly, the resulting list:
<OUTPUT> <(> <i> <)>
is /not/ scanned again.
<cut>
> #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, );
> }
In this case, the token list that results from parameter substitution is:
<OUTPUT> <(> <x> <)>
and, since the list /is/ re-scanned after parameter substitution, the
invocation of the function-like macro is seen and replaced.
<cut>
> 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?
It's not really about what's empty and what isn't. I hope the above
explains it though.
--
Ben.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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