Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #102344
| From | BartC <bc@freeuk.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Preprocessor expressions |
| Date | 2017-01-22 17:38 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <o62qjg$ib0$1@dont-email.me> (permalink) |
| References | <o62bn5$kms$1@dont-email.me> <d4b65b12-2c67-475e-9121-8d96874df453@googlegroups.com> |
On 22/01/2017 15:52, jameskuyper@verizon.net wrote: > On Sunday, January 22, 2017 at 8:24:30 AM UTC-5, Bart wrote: >> These are the ones that occur after #if and #elif. >> >> The standard 6.10p1 says these are constant-expressions. But the latter >> (A.2.1) can apparently include casts, ++, sizeof, ., ->, [] and and all >> the rest. > > Keep in mind that, in an #if constant-expression, all of the following occur > before the condition is interpreted as a constant-expression: > 1. macros that are not the argument of the "defined" unary operator are > expanded. > 2. occurrences of the "defined" unary operator are replaced by either 0 or 1, > depending upon whether or not it's argument matches the name of a defined macro. > 3. All remaining identifiers are replaced with the pp-number 0. This occurs > BEFORE conversion of pre-processing tokens into tokens (6.10.1p4). > Keep in mind that keywords qualify only as tokens, and not as pre-processing > tokens (6.4p1). At this point in the translation process, things that will > later be identified as keywords are parsed only as identifiers - and the > conversion described above applies to those identifiers. > > Therefore, (struct tm*) would be converted to (0 0*), and (int (*)(double)) > would be converted to (0(*)(0), both of which are syntax errors. Offhand, I > don't see any way for a #if condition to contain an actual cast. > > For both the prefix and postfix versions of the ++ and -- operators, there is a > constraint that their argument be a modifiable lvalue. With all identifiers > converted to 0, how could that constraint ever be satisfied? > > For both the "." and "->", the left operand is required to have a struct or > union type. With all identifiers (including typedefs, struct and union tags, > and all of the keywords used to specify types) replaced with 0, how could you > form such an operand? OK, thanks. That's starting to make more sense (but a dedicated grammar for pp expressions I think would have been useful). > With all identifiers converted to 0, the only way to form an array is using a > string literal. "abcdef"[0] is therefore permitted in a #if. gcc (and most compilers I've tried) tells me that "abcdef" is not a valid pp token. And neither is "[", "->", ".", "++" and so on. (I've been using trial and error to figure these things out, to try and build a reduced syntax for these expressions.) -- Bartc
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Preprocessor expressions BartC <bc@freeuk.com> - 2017-01-22 13:24 +0000
Re: Preprocessor expressions jameskuyper@verizon.net - 2017-01-22 07:52 -0800
Re: Preprocessor expressions Ralf Damaschke <rwspam@gmx.de> - 2017-01-22 17:15 +0000
Re: Preprocessor expressions "James R. Kuyper" <jameskuyper@verizon.net> - 2017-01-22 13:32 -0500
Re: Preprocessor expressions BartC <bc@freeuk.com> - 2017-01-22 17:38 +0000
Re: Preprocessor expressions Thiago Adams <thiago.adams@gmail.com> - 2017-02-01 03:12 -0800
Re: Preprocessor expressions Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-02-01 11:44 +0000
Re: Preprocessor expressions BartC <bc@freeuk.com> - 2017-02-01 11:56 +0000
Re: Preprocessor expressions jameskuyper@verizon.net - 2017-02-01 08:35 -0800
Re: Preprocessor expressions Thiago Adams <thiago.adams@gmail.com> - 2017-02-02 09:23 -0800
Re: Preprocessor expressions BartC <bc@freeuk.com> - 2017-02-02 18:14 +0000
Re: Preprocessor expressions Keith Thompson <kst-u@mib.org> - 2017-02-02 10:35 -0800
Re: Preprocessor expressions Thiago Adams <thiago.adams@gmail.com> - 2017-02-02 17:09 -0800
Re: Preprocessor expressions Thiago Adams <thiago.adams@gmail.com> - 2017-02-05 10:09 -0800
Re: Preprocessor expressions Thiago Adams <thiago.adams@gmail.com> - 2017-02-05 10:38 -0800
Re: Preprocessor expressions Thiago Adams <thiago.adams@gmail.com> - 2017-02-05 11:03 -0800
Re: Preprocessor expressions BartC <bc@freeuk.com> - 2017-02-06 15:17 +0000
Re: Preprocessor expressions Thiago Adams <thiago.adams@gmail.com> - 2017-02-07 05:36 -0800
Re: Preprocessor expressions BartC <bc@freeuk.com> - 2017-02-07 21:01 +0000
Re: Preprocessor expressions supercat@casperkitty.com - 2017-02-07 13:16 -0800
Re: Preprocessor expressions BartC <bc@freeuk.com> - 2017-02-07 22:09 +0000
Re: Preprocessor expressions supercat@casperkitty.com - 2017-02-07 14:33 -0800
Re: Preprocessor expressions Keith Thompson <kst-u@mib.org> - 2017-02-07 14:52 -0800
Re: Preprocessor expressions BartC <bc@freeuk.com> - 2017-02-08 00:13 +0000
Re: Preprocessor expressions Keith Thompson <kst-u@mib.org> - 2017-02-07 16:39 -0800
Re: Preprocessor expressions jameskuyper@verizon.net - 2017-02-07 16:47 -0800
Re: Preprocessor expressions David Brown <david.brown@hesbynett.no> - 2017-02-08 10:03 +0100
Re: Preprocessor expressions Keith Thompson <kst-u@mib.org> - 2017-02-08 09:19 -0800
Re: Preprocessor expressions Thiago Adams <thiago.adams@gmail.com> - 2017-02-08 12:35 -0800
Re: Preprocessor expressions Thiago Adams <thiago.adams@gmail.com> - 2017-02-09 05:25 -0800
Re: Preprocessor expressions supercat@casperkitty.com - 2017-02-09 07:37 -0800
Re: Preprocessor expressions BartC <bc@freeuk.com> - 2017-02-09 15:52 +0000
Re: Preprocessor expressions BartC <bc@freeuk.com> - 2017-01-22 19:34 +0000
Re: Preprocessor expressions jameskuyper@verizon.net - 2017-01-22 13:01 -0800
Re: Preprocessor expressions Tim Rentsch <txr@alumni.caltech.edu> - 2017-01-30 05:30 -0800
csiph-web