2

In C++,

is 
(a+++b)
processed as 
((a++) + b) 
or 
(a + (++b))

Where is this clarified in the standard?


the first part of this question has many answers, but the specific question WHERE IN THE STANDARD IS THIS CLARIFIED is not answered very clearly elsewhere.

for those interested, it is at 2.4.3 in the 2003 C++ standard (ISO/IEC 14882)

"If the input stream has been parsed into preprocessing tokens up to a given character, the next preprocessing token is the longest sequence of characters that could constitute a preprocessing token, even if that would cause further lexical analysis to fail."

Cœur
  • 37,241
  • 25
  • 195
  • 267
matt
  • 4,042
  • 5
  • 32
  • 50
  • 4
    Why write such code that is difficult to understand – Ed Heal Mar 09 '15 at 06:18
  • 2
    I wouldn't, but someone might. – matt Mar 09 '15 at 06:19
  • 2
    I have this great rule to writing C++: don't write weird things. This would be an example of a weird thing. If you can't immediately tell by looking at it what's happening then simply don't do it and resort to simpler and more straightforward ways, it avoids making mistakes like these. – sim642 Mar 09 '15 at 06:20
  • @samgak, Java is not C++ and could have totally different rules for expressions like these. – sim642 Mar 09 '15 at 06:22
  • writing a parser and it interested me – matt Mar 09 '15 at 06:38
  • The C++ standard almost takes this identically even the examples from the [C standard](http://stackoverflow.com/a/24947922/1708801) – Shafik Yaghmour Mar 09 '15 at 09:38

1 Answers1

5

It is a++ +b, because the tokenizer is greedy and will try to match ++ wherever possible.