peculiar problem with expression evaluation

Discussion in 'C Programming' started by sarab.nsit@gmail.com, Aug 21, 2007.

  1. Guest

    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, 2007
    #1
    1. Advertising

  2. Ian Collins Guest

    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.
     
    Ian Collins, Aug 21, 2007
    #2
    1. Advertising

  3. Guest

    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, 2007
    #3
  4. Mark Bluemel Guest

    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
     
    Mark Bluemel, Aug 21, 2007
    #4
  5. Richard Guest

    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.
     
    Richard, Aug 21, 2007
    #5
  6. Richard Guest

    Ian Collins <> 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.
     
    Richard, Aug 21, 2007
    #6
  7. >>>>> "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
     
    Charlton Wilbur, Aug 21, 2007
    #7
  8. Ian Collins Guest

    Richard wrote:
    > Ian Collins <> 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.


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

    --
    Ian Collins.
     
    Ian Collins, Aug 21, 2007
    #8
  9. CBFalconer Guest

    "" 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
     
    CBFalconer, Aug 21, 2007
    #9
  10. Richard wrote:
    > Ian Collins <> 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.
     
    Martin Ambuhl, Aug 21, 2007
    #10
  11. Richard Guest

    Martin Ambuhl <> writes:

    > Richard wrote:
    >> Ian Collins <> 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


    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.

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


    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.
     
    Richard, Aug 21, 2007
    #11
  12. Old Wolf Guest

    On Aug 22, 9:50 am, Richard <> wrote:
    > 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.
     
    Old Wolf, Aug 21, 2007
    #12
  13. Old Wolf Guest

    Old Wolf, Aug 21, 2007
    #13
  14. Richard <> writes:
    [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) <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"
     
    Keith Thompson, Aug 21, 2007
    #14
  15. CBFalconer Guest

    Old Wolf wrote:
    > On Aug 22, 9:50 am, Richard <> wrote:
    >

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


    So annoying that he is plonked here. Reduces the irritation.

    --
    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
     
    CBFalconer, Aug 22, 2007
    #15
  16. Army1987 Guest

    On Tue, 21 Aug 2007 17:31:27 +0200, Richard wrote:

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

    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
     
    Army1987, Aug 22, 2007
    #16
  17. Default User Guest

    Keith Thompson wrote:

    > Richard <> writes:
    > [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
     
    Default User, Aug 22, 2007
    #17
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Richard K Bethell
    Replies:
    4
    Views:
    399
  2. Randy Smith
    Replies:
    0
    Views:
    648
    Randy Smith
    Apr 28, 2005
  3. Ilias Lazaridis
    Replies:
    2
    Views:
    397
    Ilias Lazaridis
    Apr 24, 2005
  4. Ilias Lazaridis
    Replies:
    74
    Views:
    779
    Ilias Lazaridis
    Apr 4, 2005
  5. Ilias Lazaridis
    Replies:
    18
    Views:
    355
    Bill Guindon
    Apr 9, 2005
Loading...

Share This Page