peculiar problem with expression evaluation

S

sarab.nsit

Hi All,

I observed something surprising:
Here is code snippet

*****************
int i = 5;
i = i++ + ((((8 << 1) << (5 << 1)) * 3 * 3)) + ++i;
printf ( "i = %d \n " ,i);
*****************
output
i = 147469


But if i just assign the middle expression i.e. ((((8 << 1) << (5 <<
1)) * 3 * 3)) to an integer k my output changes

**************
int i = 5;
int k = 0;
k = ((((8 << 1) << (5 << 1)) * 3 * 3));
i = i++ + k + ++i;
printf ( "i = %d \n " ,i);
***************
output
i = 147468

As far as i know postfix increment should evaluate only at the end of
expression as in case 2 . but in case 1 it is getting incremented
during evaluation .

I am not able to figure out why i am getting this difference in
output.

Thanks in advance
Sarab
 
I

Ian Collins

Hi All,

I observed something surprising:
Here is code snippet

*****************
int i = 5;
i = i++ + ((((8 << 1) << (5 << 1)) * 3 * 3)) + ++i;
printf ( "i = %d \n " ,i);
*****************

Please see the scores of previous postings about this form of undefined
behavior.
 
S

sarab.nsit

Forgot to tell my compiler version . i am using gcc compiler i.e.
gcc (GCC) 3.2.3 20030502 (Red Hat Linux 3.2.3-47)
 
M

Mark Bluemel

Forgot to tell my compiler version . i am using gcc compiler i.e.
gcc (GCC) 3.2.3 20030502 (Red Hat Linux 3.2.3-47)
We don't care about that. What version of the C standard did you
consult? What version of the C-FAQ did you neglect to read?

Some suggestions:-

* Read the FAQ at c-faq.com

* Search this group in Google for "sequence point"

* Don't waste our time and network bandwidth
 
R

Richard

Mark Bluemel said:
We don't care about that. What version of the C standard did you
consult? What version of the C-FAQ did you neglect to read?

Some suggestions:-

* Read the FAQ at c-faq.com

* Search this group in Google for "sequence point"

* Don't waste our time and network bandwidth

You are a tit of the first order.
 
R

Richard

Ian Collins said:
Please see the scores of previous postings about this form of undefined
behavior.

By this rational, you should post this reply to 99% of posts which
cover material already covered and archived. If *you* are tired of
answering these questions I suggest you have one of two options:

a) Leave
b) Leave it to someone else to answer.

A noob might have no experience to spot the issue. It IS a common
issue. It is not necessarily easy to find. No one should be expected to
memorise a FAQ before posting to a help news group.
 
C

Charlton Wilbur

R> A noob might have no experience to spot the issue. It IS a
R> common issue. It is not necessarily easy to find. No one should
R> be expected to memorise a FAQ before posting to a help news
R> group.

No, but everyone *is* expected to *consult* a FAQ before posting to a
news group. Doing so makes memorizing the FAQ unnecessary.

Charlton
 
I

Ian Collins

Richard said:
A noob might have no experience to spot the issue. It IS a common
issue. It is not necessarily easy to find. No one should be expected to
memorise a FAQ before posting to a help news group.

Bollocks code like that common? Good to know there'll be plenty of work
fixing it...
 
M

Martin Ambuhl

Richard said:
By this rational, you should post this reply to 99% of posts which
cover material already covered and archived. If *you* are tired of
answering these questions I suggest you have one of two options:

a) Leave
b) Leave it to someone else to answer.

I suggest you be condemned to spend the rest of your life answering the
same questions over and over. The fact is that (b) is covered by the
FAQ, but not by you, who as usual; carps without contributing anything.
You will note that you did *nothing* toward answering the origianl
question. Your behavior is nothing but destructive.
A noob might have no experience to spot the issue. It IS a common
issue. It is not necessarily easy to find. No one should be expected to
memorise a FAQ before posting to a help news group.

And what, exactly, did *you* contribute to answering the question?
Nothing. You have only negativism to offer. Twit.
 
R

Richard

Martin Ambuhl said:
I suggest you be condemned to spend the rest of your life answering
the same questions over and over. The fact is that (b) is covered by
the FAQ, but not by you, who as usual; carps without contributing

Nearly all bloody questions here are covered by the FAQ. People,
especially nOObs, find it hard to locate their problems and to digest
entire FAQs. It's why help groups exist. It costs nothing to be
polite. Don't want to help? Then don't.

The "its already been answered" line would apply to 99.9999% of
questions posted here.
anything. You will note that you did *nothing* toward answering the
origianl question. Your behavior is nothing but destructive.

Pointing out rude and obnoxious behaviour and requesting a poster to
turn it down a bit is not destructive. It is also amusing that you are
now doing exactly what you are accusing me of. The difference being that
I am asking for some politeness and thoughtfulness when replying as
opposed to berating them for not being fully clued up on the
FAQ. Whereas you are supporting curt rude replies to people looking for
help because they haven't fulfilled your own requirements on doing their
own research.
And what, exactly, did *you* contribute to answering the question?

I wasn't answering the question. I was answering his arrogant post. Your
point is what exactly?
Nothing. You have only negativism to offer. Twit.

And the OP was positive in what way? It was rude and obnoxious. my post
was in no way negative as far as the OP goes. It was curt with the poster
who felt the need to be unnecessarily rude to the OP.

And I frequently post on topic comments. I just don't feel the need to
jump in and berate nOObs like some, too frequently, do. I also don't feel
the need to repeat an answer that someone else has already
addressed. And just by hanging around I learn a lot here too.

Bottom line : If you can't be nice, say nothing at all.

So basically, you are as bad as the previous poster.

I am astonished at the attitude of some people in this NG. I have not
witnessed such a level of arrogant posturing and downright rudeness in
any other technical group in which I participate. And as usual it's a
small minority who leave the bad taste.
 
O

Old Wolf

I also don't feel the need to repeat an answer that someone
else has already addressed.

Yet you criticise Ian Collins for NOT repeating
the answer that's been addressed hundreds of times
already. Nice work, Einstein
Bottom line : If you can't be nice, say nothing at all.

Nobody believes people who don't follow their own advice.
I am astonished at the attitude of some people in this NG. I have not
witnessed such a level of arrogant posturing and downright rudeness in
any other technical group in which I participate.

You're the worst of them.
 
K

Keith Thompson

Richard said:
And I frequently post on topic comments. I just don't feel the need to
jump in and berate nOObs like some, too frequently, do. I also don't feel
the need to repeat an answer that someone else has already
addressed. And just by hanging around I learn a lot here too.

Bottom line : If you can't be nice, say nothing at all.
[...]

Time for me to exhibit some more foolish optimism ...

Richard, I've occasionally seen you post topical comments, but it
seems to me that the vast majority of your posts (at least recently)
are complaints about other people's complaints. If you followed your
own advice, "If you can't be nice, say nothing at all", then you would
post far less than you do (and your S/N ratio would rise
considerably). I fail to see how berating the regulars, as you do, is
so much better than berating newbies. You ask us to ignore posts that
we think are inappropriate, yet you spend a great deal of time
responding to posts that you think are inappropriate.

Please give it some thought.
 
A

Army1987

By this rational, you should post this reply to 99% of posts which
cover material already covered and archived. If *you* are tired of
answering these questions I suggest you have one of two options:

a) Leave
b) Leave it to someone else to answer.

A noob might have no experience to spot the issue. It IS a common
issue. It is not necessarily easy to find. No one should be expected to
memorise a FAQ before posting to a help news group.
Yeah, everybody tries to assign three different values to the same
variable at once and are surprised to see that the result is not
what they expected... (And everybody tries to stuff 9 * 2**40 in
an int...)
 
D

Default User

Keith said:
[snip]
Bottom line : If you can't be nice, say nothing at all.
[...]

Time for me to exhibit some more foolish optimism ...

Richard, I've occasionally seen you post topical comments, but it
seems to me that the vast majority of your posts (at least recently)
are complaints about other people's complaints.


Seems obvious to me that he's been trolling for some time now. That's
why I plonked him quite a while back.




Brian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top