From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,ace3fca092a457cd X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!r34g2000hsd.googlegroups.com!not-for-mail From: Maciej Sobczak Newsgroups: comp.lang.ada Subject: Re: Unary operator after binary operator: legal or not? => Compiler Error Date: Wed, 01 Aug 2007 00:16:41 -0700 Organization: http://groups.google.com Message-ID: <1185952601.476211.72590@r34g2000hsd.googlegroups.com> References: <1185901323.18398.4.camel@kartoffel> <1185909474.208950.99070@d30g2000prg.googlegroups.com> NNTP-Posting-Host: 137.138.37.241 Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" X-Trace: posting.google.com 1185952601 28850 127.0.0.1 (1 Aug 2007 07:16:41 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 1 Aug 2007 07:16:41 +0000 (UTC) In-Reply-To: <1185909474.208950.99070@d30g2000prg.googlegroups.com> User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.12) Gecko/20070724 Red Hat/1.5.0.12-0.3.slc3 Firefox/1.5.0.12,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: r34g2000hsd.googlegroups.com; posting-host=137.138.37.241; posting-account=ps2QrAMAAAA6_jCuRt2JEIpn5Otqf_w0 Xref: g2news2.google.com comp.lang.ada:1310 Date: 2007-08-01T00:16:41-07:00 List-Id: On 31 Lip, 21:17, Adam Beneschan wrote: > What I can't figure out is, my C compiler accepts "c = a+++b" Yes. > but it > doesn't > seem to accept "c = a+++++b" Right. > which should clearly be equivalent to > c = (a++) + (++b). Why do you think so? On what basis? The C (and C++) parser is greedy, which means that it tries to eat as much as it can to get the valid token. The first two pluses in 'a++++ +b' give a single token '++'. The next two pluses give another *valid* token, which is again '++'. And so on. The only problem is that two such tokens one after another, while still being *valid* tokens, do not form a valid expression (cannot post-increment the r-value that results from the first post-increment). Note that you can/should write: c = a++ + ++b; which does what you expect (except that post-increment has no benefits over pre-increment here). Hint: keep the formatting of your code readable. Your compiler just refuses the code that would be hard to read by a human being - why do you consider it to be a bug in the language? :-) -- Maciej Sobczak http://www.msobczak.com/