473,386 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

peculiar problem with expression evaluation

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

Aug 21 '07 #1
11 1168
sa********@gmail.com wrote:
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.

--
Ian Collins.
Aug 21 '07 #2
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)

Aug 21 '07 #3
sa********@gmail.com wrote:
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
Aug 21 '07 #4
Ian Collins <ia******@hotmail.comwrites:
sa********@gmail.com wrote:
>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.
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.
Aug 21 '07 #5
>>>>"R" == Richard <rg****@gmail.comwrites:

RA noob might have no experience to spot the issue. It IS a
Rcommon issue. It is not necessarily easy to find. No one should
Rbe expected to memorise a FAQ before posting to a help news
Rgroup.

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

Charlton
--
Charlton Wilbur
cw*****@chromatico.net
Aug 21 '07 #6
Richard wrote:
Ian Collins <ia******@hotmail.comwrites:
>sa********@gmail.com wrote:
>>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.


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...

--
Ian Collins.
Aug 21 '07 #7
Richard wrote:
Ian Collins <ia******@hotmail.comwrites:
>sa********@gmail.com wrote:
>>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.

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.

Aug 21 '07 #8
"sa********@gmail.com" wrote:
>
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)
So what? If you have a problem, spit it out. In this group the
actual compiler doesn't matter.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>

--
Posted via a free Usenet account from http://www.teranews.com

Aug 21 '07 #9
Richard <rg****@gmail.comwrites:
[snip]
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.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Aug 21 '07 #10
On Tue, 21 Aug 2007 17:31:27 +0200, Richard wrote:
Ian Collins <ia******@hotmail.comwrites:
>sa********@gmail.com wrote:
>>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.

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...)

--
Army1987 (Replace "NOSPAM" with "email")
No-one ever won a game by resigning. -- S. Tartakower

Aug 22 '07 #11
Keith Thompson wrote:
Richard <rg****@gmail.comwrites:
[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
Aug 22 '07 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Simon Wigzell | last post by:
A client wants have acess to an online databases records controlled by group strings and evaluation strings e.g., each use would have in his client record a group string like this: And each...
70
by: Roy Yao | last post by:
Does it mean "(sizeof(int))* (p)" or "sizeof( (int)(*p) )" ? According to my analysis, operator sizeof, (type) and * have the same precedence, and they combine from right to left. Then this...
27
by: C Gillespie | last post by:
Dear All, Hopefully I have a simple problem. Basically, I just want to alter some text with JS. Here is some of my test code: <snip> <script type="text/javascript"> var tmp='a';
8
by: manan.kathuria | last post by:
hi all , the expression in question is ++i&&++j||++k most sources say that since the result of the || operation is decided by the LHS itself , the right side is not computed my point of...
21
by: siliconwafer | last post by:
Hi, In case of following expression: c = a && --b; if a is 0,b is not evaluated and c directly becomes 0. Does this mean that && operator is given a higher precedence over '--'operator? as...
8
by: Brian Blais | last post by:
Hello, I have a string input from the user, and want to parse it to a number, and would like to know how to do it. I would like to be able to accept arithmetic operations, like: '5+5'...
8
by: junky_fellow | last post by:
Hi, Sorry, for asking similar questions again and again. 1) I want to know how should we reslove the ambiguities in a c expression ? Should we use precedence table as mentioned in K&R book ...
21
by: Steven T. Hatton | last post by:
I'm trying to improve my formal understanding of C++. One significant part of that effort involves clarifying my understanding of the vocabulary used to describe the language. This is from the...
2
by: Tim Johnson | last post by:
I'm having trouble understanding this part of the expression evaluation rules ('6.5 Expressions', second item, C99 spec; the C++ wording is presumably identical): What precisely does the...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.