Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail |
|---|---|
| From | Todd Carnes <toddcarnes@gmail.com> |
| Newsgroups | comp.lang.c |
| Subject | Re: confusion about behavior |
| Date | Mon, 15 Aug 2011 02:26:34 +0000 (UTC) |
| Organization | Aioe.org NNTP Server |
| Lines | 47 |
| Message-ID | <pan.2011.08.15.02.26.35@gmail.com> (permalink) |
| References | <cda0e503-482a-4075-b3fa-af3013819716@l11g2000prh.googlegroups.com> <j296jn$p5q$1@dont-email.me> |
| 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:9415 |
Show key headers only | View raw
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).
Ok, I ran the code below and got 5, just like you said it would be. Keith
already explained why. I got the pre- and post- increment thing wrong.
Todd
#include <stdio.h>
int main(int argc, char **argv)
{
int a = 2;
int b = 3;
int c;
c = a+++b;
printf("c = %i", c);
return 0;
}
Back to comp.lang.c | Previous | Next — Previous in thread | Find similar | Unroll thread
confusion about behavior LJ <djtheshowstopper@gmail.com> - 2011-08-14 11:56 -0700
Re: confusion about behavior China Blue Tip Wrench <chine.bleu@yahoo.com> - 2011-08-14 12:05 -0700
Re: confusion about behavior Keith Thompson <kst-u@mib.org> - 2011-08-14 12:06 -0700
Re: confusion about behavior Todd Carnes <toddcarnes@gmail.com> - 2011-08-15 01:57 +0000
Re: confusion about behavior Keith Thompson <kst-u@mib.org> - 2011-08-14 19:10 -0700
Re: confusion about behavior Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-08-15 03:44 +0100
Re: confusion about behavior Keith Thompson <kst-u@mib.org> - 2011-08-14 20:27 -0700
Re: confusion about behavior Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-08-14 22:52 -0400
Re: confusion about behavior Seebs <usenet-nospam@seebs.net> - 2011-08-15 04:28 +0000
Re: confusion about behavior Kenneth Brody <kenbrody@spamcop.net> - 2011-08-15 15:31 -0400
Re: confusion about behavior Keith Thompson <kst-u@mib.org> - 2011-08-15 12:36 -0700
Re: confusion about behavior Seebs <usenet-nospam@seebs.net> - 2011-08-15 20:33 +0000
Re: confusion about behavior Kenneth Brody <kenbrody@spamcop.net> - 2011-08-16 14:39 -0400
Re: confusion about behavior Keith Thompson <kst-u@mib.org> - 2011-08-16 12:27 -0700
Re: confusion about behavior Willem <willem@toad.stack.nl> - 2011-08-16 19:47 +0000
Re: confusion about behavior Barry Schwarz <schwarz45@yahoo.com> - 2011-09-05 04:50 -0700
[OT] Re: confusion about behavior Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-09-05 09:07 -0400
Re: confusion about behavior Kenneth Brody <kenbrody@spamcop.net> - 2011-09-06 12:42 -0400
Re: confusion about behavior James Kuyper <jameskuyper@verizon.net> - 2011-08-14 15:10 -0400
Re: confusion about behavior Todd Carnes <toddcarnes@gmail.com> - 2011-08-15 02:04 +0000
Re: confusion about behavior Keith Thompson <kst-u@mib.org> - 2011-08-14 19:15 -0700
Re: confusion about behavior Todd Carnes <toddcarnes@gmail.com> - 2011-08-15 02:34 +0000
Re: confusion about behavior James Kuyper <jameskuyper@verizon.net> - 2011-08-14 22:37 -0400
Re: confusion about behavior Todd Carnes <toddcarnes@gmail.com> - 2011-08-15 02:26 +0000
csiph-web