Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

i+=i+++++i ?

131 views
Skip to first unread message

Alo Raidaru

unread,
Jun 27, 2005, 4:15:07 PM6/27/05
to
#include <stdio.h>
int main(int argc, char *argv[]){
int i;

i=3;
i+=(i++)+(++i);
printf("i+=(i++)+(++i); \ti %d\n", i);

i=3;
i+=(++i)+(i++);
printf("i+=(++i)+(i++); \ti %d\n", i);

i=3;
i+=i++ + ++i;
printf("i+=i++ + ++i; \ti %d\n", i);

i=3;
i=i+ i++ + ++i;
printf("i=i+ i++ + ++i; \ti %d\n", i);

i=3;
i=i++ + ++i +i;
printf("i=i++ + ++i +i; \ti %d\n", i);

return 1;
}

****************************
XP MS QC 19.12.1988 11:59
i+=(i++)+(++i); i 13
i+=(++i)+(i++); i 13
i+=i++ + ++i; i 13
i=i+ i++ + ++i; i 13
i=i++ + ++i +i; i 13

XP gcc 16.12.1996 12:49
i+=(i++)+(++i); i 13
i+=(++i)+(i++); i 13
i+=i++ + ++i; i 13
i=i+ i++ + ++i; i 11
i=i++ + ++i +i; i 13

XP LCC-32 09.08.2004 10:01
i+=(i++)+(++i); i 11
i+=(++i)+(i++); i 11
i+=i++ + ++i; i 11
i=i+ i++ + ++i; i 11
i=i++ + ++i +i; i 13

? :)

A.R.

Dave Hansen

unread,
Jun 27, 2005, 5:08:05 PM6/27/05
to
On Mon, 27 Jun 2005 23:15:07 +0300, Alo Raidaru <alo.r...@ut.ee>
wrote:

[...etc...]


>
>XP LCC-32 09.08.2004 10:01
>i+=(i++)+(++i); i 11
>i+=(++i)+(i++); i 11
>i+=i++ + ++i; i 11
>i=i+ i++ + ++i; i 11
>i=i++ + ++i +i; i 13

Google "undefined behavior." You might find your program listed as an
example...

Regards,

-=Dave
--
Change is inevitable, progress is not.

jacob navia

unread,
Jun 27, 2005, 5:54:34 PM6/27/05
to
You can't use increment or decrement operators more
than once in an expression.

CBFalconer

unread,
Jun 27, 2005, 6:05:54 PM6/27/05
to
Alo Raidaru wrote:
>
> #include <stdio.h>
> int main(int argc, char *argv[]){
> int i;
>
> i=3;
> i+=(i++)+(++i);
> printf("i+=(i++)+(++i); \ti %d\n", i);
>
> i=3;
> i+=(++i)+(i++);
> printf("i+=(++i)+(i++); \ti %d\n", i);
>
> i=3;
> i+=i++ + ++i;
> printf("i+=i++ + ++i; \ti %d\n", i);
>
> i=3;
> i=i+ i++ + ++i;
> printf("i=i+ i++ + ++i; \ti %d\n", i);
>
> i=3;
> i=i++ + ++i +i;
> printf("i=i++ + ++i +i; \ti %d\n", i);
>
> return 1;
> }

Every statement, apart from i = 3, invokes undefined (or, for the
return, implementation defined) behaviour. If you write
illegitimate code, why do you expect answers?

--
"I'm a war president. I make decisions here in the Oval Office
in foreign policy matters with war on my mind." - GWB 2004-2-8
"If I knew then what I know today, I would still have invaded
Iraq. It was the right decision" - G.W. Bush, 2004-08-02
"This notion that the United States is getting ready to attack
Iran is simply ridiculous. And having said that, all options
are on the table." - George W. Bush, Brussels, 2005-02-22

Randy Howard

unread,
Jun 28, 2005, 3:28:36 PM6/28/05
to
In article <d9pmod$c27$1...@kadri.ut.ee>, alo.r...@ut.ee says...

> #include <stdio.h>
> int main(int argc, char *argv[]){
> int i;
>
> i=3;
> i+=(i++)+(++i);
> printf("i+=(i++)+(++i); \ti %d\n", i);

[snip]

Get a new professor. This one is screwing you.

--
Randy Howard (2reply remove FOOBAR)
"I don't really care about being right you know,
I just care about success." --Steve Jobs

toby

unread,
Jun 29, 2005, 5:24:18 PM6/29/05
to

jacob navia wrote:
> You can't use increment or decrement operators more
> than once in an expression.

On the same object, that is.

The OP should also look up "sequence points".

--Toby

Alo Raidaru

unread,
Jun 29, 2005, 5:49:19 PM6/29/05
to
toby wrote:
>
> jacob navia wrote:
>
>>You can't use increment or decrement operators more
>>than once in an expression.
>
> On the same object, that is.

And not add a+b+c :)
http://www.lysator.liu.se/c/rat/c3.html#3-3

Ohhh. :(

A.R.

0 new messages