Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #101195
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: 'Amalgamated' source code |
| Date | 2017-01-05 19:33 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <87k2a9i9ne.fsf@bsb.me.uk> (permalink) |
| References | (10 earlier) <o4io7d$c95$1@dont-email.me> <c901fe2c-600f-430c-be7c-3bfc274e06e3@googlegroups.com> <8b7b2773-2a60-44c5-a9f4-e5fa23eff966@googlegroups.com> <87bmvlk2cr.fsf@bsb.me.uk> <o4m0c3$saf$1@dont-email.me> |
BartC <bc@freeuk.com> writes: > On 05/01/2017 14:28, Ben Bacarisse wrote: >> Thiago Adams <thiago.adams@gmail.com> writes: >> <snip> >>> I did one more sample to see what happens: >>> >>> #define M(a) X##a >>> #define M2(a, b) #a a b >>> >>> M2( M ( 1), M(1)) >>> >>> VC++ preprocessor output: >>> >>> "M ( 1)" X1 X1 >>> >>> The same argument 'a' for macro can or not be expanded before >>> the macro invocation. >>> >>> Today I keep a map "parameter-name:a" - > "expanded:X1" >>> >>> To fix my preprocessor I will keep both: >>> >>> "parameter-name:a" - > ["expanded:X1", "not expanded:M ( 1)"] >>> >>> and use the appropriated value depending on #a or a. >> >> That seems like a very odd way to do it. Have you read what the C >> standard says about macro expansion? It explains the algorithm quite >> well, in my option. > > I couldn't make head or tail of it (6.10.3.1): > > "A parameter in the replacement list, unless ... is replaced by the > corresponding argument after all macros contained therein have been > expanded. Before being substituted, each argument’s preprocessing > tokens are completely macro replaced as if they formed the rest of the > preprocessing file; no other preprocessing tokens are available." > > What does the second sentence mean; is it just restating what happens > in the first? It says a bit more than the first. In particular it says the each argument's token list is treated separately and like a file on it's own. Maybe you never thought otherwise but perhaps that's been the source of some confusion in that past. > And that's not all of it; the process continues in > 6.10.3.4. > > Here's how the gnu CPP docs explain it; I think this covers all of it > apart from # and ##: But # and ## are the problem here. It's much easier to explain expansion while ignoring or glossing over # and ##. > "All arguments to a macro are completely macro-expanded before they > are substituted into the macro body. After substitution, the complete > text is scanned again for macros to expand, including the arguments." > > Of course I will have to try out this second scheme to see if handles > all the tricky examples. It's not hard to describe in broad terms. The problem is saying exactly what happens and in what order. If the gcc docs helps then I think that's great. -- Ben.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
'Amalgamated' source code BartC <bc@freeuk.com> - 2017-01-03 15:14 +0000
Re: 'Amalgamated' source code Thiago Adams <thiago.adams@gmail.com> - 2017-01-03 08:47 -0800
Re: 'Amalgamated' source code BartC <bc@freeuk.com> - 2017-01-03 19:47 +0000
Re: 'Amalgamated' source code Thiago Adams <thiago.adams@gmail.com> - 2017-01-03 12:48 -0800
Re: 'Amalgamated' source code BartC <bc@freeuk.com> - 2017-01-03 21:36 +0000
Re: 'Amalgamated' source code Thiago Adams <thiago.adams@gmail.com> - 2017-01-03 16:01 -0800
Re: 'Amalgamated' source code Keith Thompson <kst-u@mib.org> - 2017-01-03 16:26 -0800
Re: 'Amalgamated' source code Thiago Adams <thiago.adams@gmail.com> - 2017-01-03 18:00 -0800
Re: 'Amalgamated' source code Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-01-04 03:34 +0000
Re: 'Amalgamated' source code Thiago Adams <thiago.adams@gmail.com> - 2017-01-04 03:31 -0800
Re: 'Amalgamated' source code BartC <bc@freeuk.com> - 2017-01-04 12:03 +0000
Re: 'Amalgamated' source code Thiago Adams <thiago.adams@gmail.com> - 2017-01-04 05:00 -0800
Re: 'Amalgamated' source code Thiago Adams <thiago.adams@gmail.com> - 2017-01-05 02:38 -0800
Re: 'Amalgamated' source code Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-01-05 14:28 +0000
Re: 'Amalgamated' source code supercat@casperkitty.com - 2017-01-05 08:20 -0800
Re: 'Amalgamated' source code Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-01-05 17:05 +0000
Re: 'Amalgamated' source code supercat@casperkitty.com - 2017-01-05 10:11 -0800
Re: 'Amalgamated' source code Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-01-05 19:46 +0000
Re: 'Amalgamated' source code Thiago Adams <thiago.adams@gmail.com> - 2017-01-05 12:15 -0800
Re: 'Amalgamated' source code Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-01-05 21:54 +0000
Re: 'Amalgamated' source code BartC <bc@freeuk.com> - 2017-01-05 17:40 +0000
Re: 'Amalgamated' source code Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-01-05 19:33 +0000
Re: 'Amalgamated' source code BartC <bc@freeuk.com> - 2017-01-04 10:53 +0000
Re: 'Amalgamated' source code Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-01-04 01:51 +0000
Re: 'Amalgamated' source code BartC <bc@freeuk.com> - 2017-01-04 11:54 +0000
Re: 'Amalgamated' source code Thiago Adams <thiago.adams@gmail.com> - 2017-01-04 05:57 -0800
Re: 'Amalgamated' source code BartC <bc@freeuk.com> - 2017-01-04 14:20 +0000
Re: 'Amalgamated' source code BartC <bc@freeuk.com> - 2017-01-04 15:07 +0000
Re: 'Amalgamated' source code Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-01-04 15:34 +0000
Re: 'Amalgamated' source code Thiago Adams <thiago.adams@gmail.com> - 2017-01-04 08:03 -0800
Re: 'Amalgamated' source code Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-01-04 17:09 +0000
Re: 'Amalgamated' source code bart4858@gmail.com - 2017-01-04 08:54 -0800
Re: 'Amalgamated' source code Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-01-04 17:22 +0000
Re: 'Amalgamated' source code Thiago Adams <thiago.adams@gmail.com> - 2017-01-04 07:55 -0800
Re: 'Amalgamated' source code BartC <bc@freeuk.com> - 2017-01-05 18:04 +0000
Re: 'Amalgamated' source code Thiago Adams <thiago.adams@gmail.com> - 2017-01-05 11:50 -0800
Re: 'Amalgamated' source code Jorgen Grahn <grahn+nntp@snipabacken.se> - 2017-01-04 16:29 +0000
Re: 'Amalgamated' source code bart4858@gmail.com - 2017-01-04 09:15 -0800
Re: 'Amalgamated' source code Ian Collins <ian-news@hotmail.com> - 2017-01-05 08:33 +1300
Re: 'Amalgamated' source code BartC <bc@freeuk.com> - 2017-01-04 20:26 +0000
Re: 'Amalgamated' source code supercat@casperkitty.com - 2017-01-04 13:09 -0800
Re: 'Amalgamated' source code Ian Collins <ian-news@hotmail.com> - 2017-01-05 10:21 +1300
Re: 'Amalgamated' source code supercat@casperkitty.com - 2017-01-04 13:51 -0800
Re: 'Amalgamated' source code BartC <bc@freeuk.com> - 2017-01-04 22:02 +0000
Re: 'Amalgamated' source code Ian Collins <ian-news@hotmail.com> - 2017-01-05 11:15 +1300
Re: 'Amalgamated' source code Jorgen Grahn <grahn+nntp@snipabacken.se> - 2017-01-07 06:38 +0000
Re: 'Amalgamated' source code BartC <bc@freeuk.com> - 2017-01-07 11:35 +0000
Re: 'Amalgamated' source code supercat@casperkitty.com - 2017-01-04 09:53 -0800
Re: 'Amalgamated' source code Malcolm McLean <malcolm.mclean5@btinternet.com> - 2017-01-04 11:50 -0800
Re: 'Amalgamated' source code raltbos@xs4all.nl (Richard Bos) - 2017-01-10 01:34 +0000
Re: 'Amalgamated' source code Malcolm McLean <malcolm.mclean5@btinternet.com> - 2017-01-10 01:59 -0800
Re: 'Amalgamated' source code Les Cargill <lcargill99@comcast.com> - 2017-01-10 06:55 -0600
Re: 'Amalgamated' source code Richard Heathfield <rjh@cpax.org.uk> - 2017-01-10 14:48 +0000
Re: 'Amalgamated' source code Thiago Adams <thiago.adams@gmail.com> - 2017-04-26 07:17 -0700
csiph-web