Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #101409
| From | BartC <bc@freeuk.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Macro Expansion |
| Date | 2017-01-11 00:06 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <o53srn$dbq$1@dont-email.me> (permalink) |
| References | (3 earlier) <o52pbd$5mp$1@dont-email.me> <35bf4dd4-b642-4a98-9d7e-f577a1667a58@googlegroups.com> <o536kt$poa$1@dont-email.me> <87shoqttsu.fsf@bsb.me.uk> <4e7e4f70-e4d8-a827-cb47-a6024dab6180@verizon.net> |
On 10/01/2017 23:51, James R. Kuyper wrote: > On 01/10/2017 05:49 PM, Ben Bacarisse wrote: >> BartC <bc@freeuk.com> writes: >> <snip> >>> In the meantime perhaps someone can explain this behaviour. >> <snip> >>> ... take this one: >>> >>> #define f a*g >>> #define g f(a) >>> f(2)(9) >>> >>> First expansion (using / to separate already processed tokens, this >>> expansion, and rest of the source): >>> >>> / 2 * g / (9) >>> >>> g is now expanded (using the (9) as the arg as it can step across that >>> / boundary) to result in: >>> >>> 2 * / f(9) / >>> >>> But this time, f *is* expanded again! To result in 2 * 9 * g. (The >>> last g is not expanded as no argument follows). >> >> I think you've got something wrong here. You probably had (at some >> time) a parameter in the definition of f or g (or both). > > This looks suspiciously similar to the example from 6.10.3.4p4, and all > of BartC's comments above make sense if this is what he's talking about: > > #define f(a) a*g > #define g(a) f(a) I think someone posted the example in the thread. My copy of the standard (2009 draft) doesn't have that. But a 2011 draft I've just looked at, does. And it gives two possible expansions, both apparently valid. So that's something I don't need to worry about (other than that the majority of compilers - including gcc - seem to support the version that my CPP test program doesn't output; they expand f() again). > instead of what he actually wrote. The point of that example is that > during preprocessing of f(2)(9) you get the following sequence of > replacements: > > f(2)(9) > 2*g(9) > 2*f(9) > > The "g" comes from the token list that replaced f(2), and recognition of > "f" as a macro is supposed to be suppressed for "2*g". However, you have > to add "(9)" to make a complete invocation of g macro, and that "(9)" > was not part that list of tokens derived from an expansion of f. Should > the expansion of a macro-invocation that is only partially derived from > a previous expansion of f() be re-scanned for occurrences of f()? In > other words, does it count as a "nested replacement" in the sense of > 6.10.3.4p2? Arguments could be given for either interpretation of > "nested", and the standard doesn't define the term. The example in > 6.10.3.4p4 is provided for the explicit purpose of pointing out that it > is implicitly unspecified. I guess then that this example (my own): #define A(x,y) if(x==y) #define B A( B 10,20); is also unspecified. Yet some compilers manage it, generating 'if(10==20);'. But others go badly wrong. -- Bartc
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Macro Expansion BartC <bc@freeuk.com> - 2017-01-07 18:35 +0000
Re: Macro Expansion Thiago Adams <thiago.adams@gmail.com> - 2017-01-07 11:23 -0800
Re: Macro Expansion Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-01-07 21:28 +0000
Re: Macro Expansion Siri Cruise <chine.bleu@yahoo.com> - 2017-01-07 11:45 -0800
Re: Macro Expansion BartC <bc@freeuk.com> - 2017-01-07 20:16 +0000
Re: Macro Expansion Siri Cruise <chine.bleu@yahoo.com> - 2017-01-07 12:23 -0800
Re: Macro Expansion BartC <bc@freeuk.com> - 2017-01-07 20:31 +0000
Re: Macro Expansion Siri Cruise <chine.bleu@yahoo.com> - 2017-01-07 12:42 -0800
Re: Macro Expansion Ian Collins <ian-news@hotmail.com> - 2017-01-08 14:42 +1300
Re: Macro Expansion BartC <bc@freeuk.com> - 2017-01-08 13:18 +0000
Re: Macro Expansion BartC <bc@freeuk.com> - 2017-01-07 20:15 +0000
Re: Macro Expansion Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-01-07 20:42 +0000
Re: Macro Expansion BartC <bc@freeuk.com> - 2017-01-07 22:50 +0000
Re: Macro Expansion Ian Collins <ian-news@hotmail.com> - 2017-01-08 11:59 +1300
Re: Macro Expansion Malcolm McLean <malcolm.mclean5@btinternet.com> - 2017-01-07 15:10 -0800
Re: Macro Expansion supercat@casperkitty.com - 2017-01-07 17:24 -0800
Re: Macro Expansion Tim Rentsch <txr@alumni.caltech.edu> - 2017-01-15 21:55 -0800
Re: Macro Expansion supercat@casperkitty.com - 2017-01-16 09:06 -0800
Re: Macro Expansion Tim Rentsch <txr@alumni.caltech.edu> - 2017-01-31 08:51 -0800
Re: Macro Expansion supercat@casperkitty.com - 2017-01-31 13:06 -0800
Re: Macro Expansion Tim Rentsch <txr@alumni.caltech.edu> - 2017-02-03 07:49 -0800
Re: Macro Expansion supercat@casperkitty.com - 2017-02-03 12:03 -0800
Re: Macro Expansion Tim Rentsch <txr@alumni.caltech.edu> - 2017-02-09 09:00 -0800
Re: Macro Expansion Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-01-08 01:37 +0000
Re: Macro Expansion Jean-Marc Bourguet <jm@bourguet.org> - 2017-01-08 10:22 +0100
Re: Macro Expansion Thiago Adams <thiago.adams@gmail.com> - 2017-01-07 12:18 -0800
Re: Macro Expansion BartC <bc@freeuk.com> - 2017-01-07 20:28 +0000
Re: Macro Expansion Thiago Adams <thiago.adams@gmail.com> - 2017-01-07 12:36 -0800
Re: Macro Expansion BartC <bc@freeuk.com> - 2017-01-07 22:59 +0000
Re: Macro Expansion Thiago Adams <thiago.adams@gmail.com> - 2017-01-08 00:20 -0800
Re: Macro Expansion BartC <bc@freeuk.com> - 2017-01-08 13:30 +0000
Re: Macro Expansion BartC <bc@freeuk.com> - 2017-01-10 14:00 +0000
Re: Macro Expansion Thiago Adams <thiago.adams@gmail.com> - 2017-01-10 07:43 -0800
Re: Macro Expansion BartC <bc@freeuk.com> - 2017-01-10 17:47 +0000
Re: Macro Expansion Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-01-10 22:49 +0000
Re: Macro Expansion BartC <bc@freeuk.com> - 2017-01-10 23:28 +0000
Re: Macro Expansion "James R. Kuyper" <jameskuyper@verizon.net> - 2017-01-10 18:51 -0500
Re: Macro Expansion BartC <bc@freeuk.com> - 2017-01-11 00:06 +0000
Re: Macro Expansion BartC <bc@freeuk.com> - 2017-01-10 20:30 +0000
Re: Macro Expansion Thiago Adams <thiago.adams@gmail.com> - 2017-04-26 10:04 -0700
Re: Macro Expansion Keith Thompson <kst-u@mib.org> - 2017-04-26 12:00 -0700
Re: Macro Expansion Thiago Adams <thiago.adams@gmail.com> - 2017-04-26 12:24 -0700
Re: Macro Expansion bartc <bc@freeuk.com> - 2017-04-26 20:12 +0100
Re: Macro Expansion Thiago Adams <thiago.adams@gmail.com> - 2017-04-26 12:34 -0700
Re: Macro Expansion jameskuyper@verizon.net - 2017-04-26 13:46 -0700
Re: Macro Expansion Jean-Marc Bourguet <jm@bourguet.org> - 2017-01-08 10:13 +0100
Re: Macro Expansion BartC <bc@freeuk.com> - 2017-01-08 13:10 +0000
Re: Macro Expansion Jean-Marc Bourguet <jm@bourguet.org> - 2017-01-08 15:51 +0100
Re: Macro Expansion BartC <bc@freeuk.com> - 2017-01-08 17:17 +0000
Re: Macro Expansion supercat@casperkitty.com - 2017-01-08 11:04 -0800
Re: Macro Expansion Malcolm McLean <malcolm.mclean5@btinternet.com> - 2017-01-08 11:10 -0800
Re: Macro Expansion supercat@casperkitty.com - 2017-01-08 14:08 -0800
Re: Macro Expansion BartC <bc@freeuk.com> - 2017-01-08 19:49 +0000
Re: Macro Expansion supercat@casperkitty.com - 2017-01-08 14:17 -0800
Re: Macro Expansion BartC <bc@freeuk.com> - 2017-01-08 19:19 +0000
Re: Macro Expansion Jean-Marc Bourguet <jm@bourguet.org> - 2017-01-08 21:43 +0100
Re: Macro Expansion supercat@casperkitty.com - 2017-01-08 10:43 -0800
Re: Macro Expansion Keith Thompson <kst-u@mib.org> - 2017-01-08 12:39 -0800
Re: Macro Expansion antispam@math.uni.wroc.pl - 2017-01-08 22:54 +0000
Re: Macro Expansion "James R. Kuyper" <jameskuyper@verizon.net> - 2017-01-08 18:36 -0500
Re: Macro Expansion antispam@math.uni.wroc.pl - 2017-01-09 01:15 +0000
Re: Macro Expansion "James R. Kuyper" <jameskuyper@verizon.net> - 2017-01-08 20:49 -0500
Re: Macro Expansion BartC <bc@freeuk.com> - 2017-01-08 23:53 +0000
Re: Macro Expansion BartC <bc@freeuk.com> - 2017-01-09 01:11 +0000
Re: Macro Expansion antispam@math.uni.wroc.pl - 2017-01-09 01:31 +0000
Re: Macro Expansion BartC <bc@freeuk.com> - 2017-01-10 11:28 +0000
csiph-web