Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail From: Todd Carnes Newsgroups: comp.lang.c Subject: Re: confusion about behavior Date: Mon, 15 Aug 2011 02:04:50 +0000 (UTC) Organization: Aioe.org NNTP Server Lines: 39 Message-ID: References: NNTP-Posting-Host: uqlV+6kNo2Z0TnMsKGN6tA.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Complaints-To: abuse@aioe.org User-Agent: Pan/0.133 (House of Butterflies) X-Notice: Filtered by postfilter v. 0.8.2 Xref: x330-a1.tempe.blueboxinc.net comp.lang.c:9412 On Sun, 14 Aug 2011 15:10:48 -0400, James Kuyper wrote: > On 08/14/2011 02:56 PM, LJ wrote: >> int a = 2; >> int b = 3; >> c = a+++b; >> What will be the value of c?? >> Shouldn't it be undefined depending upon the interpretation?? > > The C standard mandates what's called the "maximal munch" rule; "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." (6.4p4) > > Therefore, there's only one permitted way of parsing the third > statement: > > c = a++ + b; > > That's equivalent to the following statement, where I've inserted some > unnecessary parenthesis to clarify the order of operations: > > c = ((a++) + b); > > Assuming that c has an arithmetic type, the behavior of that statement > is well-defined: 'a' ends up with a value of 3, and c ends up with a > value of 5 (converted, if necessary, to whatever the type of c happens > to be). So, c would actually be equal to 6. :) c = ((a++) + b) c = ((2++) + 3) c = (3 + 3) c = 6 I never heard of the "maximal munch" thing. Thanks for the explanation. Todd