Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > peculiar problem with expression evaluation

Reply
Thread Tools

peculiar problem with expression evaluation

 
 
sarab.nsit@gmail.com
Guest
Posts: n/a
 
      08-21-2007
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

 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      08-21-2007
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.
 
Reply With Quote
 
 
 
 
sarab.nsit@gmail.com
Guest
Posts: n/a
 
      08-21-2007
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)

 
Reply With Quote
 
Mark Bluemel
Guest
Posts: n/a
 
      08-21-2007
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
 
Reply With Quote
 
Richard
Guest
Posts: n/a
 
      08-21-2007
Mark Bluemel <> writes:

> 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


You are a tit of the first order.
 
Reply With Quote
 
Richard
Guest
Posts: n/a
 
      08-21-2007
Ian Collins <ian-> writes:

> 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.
 
Reply With Quote
 
Charlton Wilbur
Guest
Posts: n/a
 
      08-21-2007
>>>>> "R" == Richard <> writes:

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


--
Charlton Wilbur

 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      08-21-2007
Richard wrote:
> Ian Collins <ian-> writes:
>
>> 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.


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

--
Ian Collins.
 
Reply With Quote
 
CBFalconer
Guest
Posts: n/a
 
      08-21-2007
"" 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

 
Reply With Quote
 
Martin Ambuhl
Guest
Posts: n/a
 
      08-21-2007
Richard wrote:
> Ian Collins <ian-> writes:
>
>> 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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Peculiar problem with refresh of sqldataadapter re: stored procedures Randy Smith ASP .Net 0 04-28-2005 05:44 PM
[EVALUATION] - E03 - jamLang Evaluation Case Applied to Python Ilias Lazaridis Python 2 04-24-2005 05:29 PM
[EVALUATION] - E04 - jamPersist Evaluation Case Applied to Ruby Ilias Lazaridis Ruby 18 04-09-2005 04:45 PM
[EVALUATION] - E03 - jamLang Evaluation Case Applied to Ruby Ilias Lazaridis Ruby 74 04-04-2005 05:29 PM
peculiar ViewState corruption problem when clients are FrameWork 1.0 Richard K Bethell ASP .Net 4 12-17-2003 08:44 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57