Help

Discussion in 'C Programming' started by Red Dragon, Nov 10, 2005.

  1. Red Dragon

    Red Dragon Guest

    Can anybody tell me
    if x = x +1 is x++
    What is x = x + 2 ?

    Thanks
    Khoon.
    Red Dragon, Nov 10, 2005
    #1
    1. Advertising

  2. Red Dragon

    Giovanni Guest

    On 11/10/05 16:49, Red Dragon wrote:
    > Can anybody tell me
    > if x = x +1 is x++
    > What is x = x + 2 ?
    >


    If applicable is: x += 2;
    Ciao
    Giovanni
    --
    A computer is like an air conditioner,
    it stops working when you open Windows.
    Registered Linux user #337974 <http://counter.li.org/>
    Giovanni, Nov 10, 2005
    #2
    1. Advertising

  3. Red Dragon wrote:
    > Can anybody tell me
    > if x = x +1 is x++


    The effect may be equivalent but in the former x is evaluated twice
    whereas in the latter x is evaluated once. Additionally, the result of
    evaluating the former is the same as ++x, not x++.

    > What is x = x + 2 ?


    x += 2.

    Robert Gamble
    Robert Gamble, Nov 10, 2005
    #3
  4. Red Dragon

    Jordan Abel Guest

    On 2005-11-10, Robert Gamble <> wrote:
    > Red Dragon wrote:
    >> Can anybody tell me
    >> if x = x +1 is x++

    >
    > The effect may be equivalent but in the former x is evaluated twice
    > whereas in the latter x is evaluated once.


    actually, no. it's read once and modified once in both cases.
    Jordan Abel, Nov 10, 2005
    #4
  5. Red Dragon

    Red Dragon Guest

    >>> Can anybody tell me
    >>> if x = x +1 is x++

    >>
    >> The effect may be equivalent but in the former x is evaluated twice
    >> whereas in the latter x is evaluated once.

    >
    > actually, no. it's read once and modified once in both cases.


    I got it. Thanks for your help.

    Regards,
    Khoon.
    Red Dragon, Nov 10, 2005
    #5
  6. Jordan Abel wrote:
    > On 2005-11-10, Robert Gamble <> wrote:
    > > Red Dragon wrote:
    > >> Can anybody tell me
    > >> if x = x +1 is x++

    > >
    > > The effect may be equivalent but in the former x is evaluated twice
    > > whereas in the latter x is evaluated once.

    >
    > actually, no. it's read once and modified once in both cases.


    As I said, x is *evaluated* twice in the first expression, once in the
    second.

    Robert Gamble
    Robert Gamble, Nov 11, 2005
    #6
  7. Red Dragon

    Guest

    Robert Gamble wrote:
    > Jordan Abel wrote:
    > > On 2005-11-10, Robert Gamble <> wrote:
    > > > Red Dragon wrote:
    > > >> Can anybody tell me
    > > >> if x = x +1 is x++
    > > >
    > > > The effect may be equivalent but in the former x is evaluated twice
    > > > whereas in the latter x is evaluated once.

    > >
    > > actually, no. it's read once and modified once in both cases.

    >
    > As I said, x is *evaluated* twice in the first expression, once in the
    > second.
    >
    > Robert Gamble


    *Evaluated * by the compiler? Or machine code? Most compilers I know
    generate the same assembly in both cases, even with optimisation turned
    off.
    , Nov 11, 2005
    #7
  8. wrote:
    > Robert Gamble wrote:
    > > Jordan Abel wrote:
    > > > On 2005-11-10, Robert Gamble <> wrote:
    > > > > Red Dragon wrote:
    > > > >> Can anybody tell me
    > > > >> if x = x +1 is x++
    > > > >
    > > > > The effect may be equivalent but in the former x is evaluated twice
    > > > > whereas in the latter x is evaluated once.
    > > >
    > > > actually, no. it's read once and modified once in both cases.

    > >
    > > As I said, x is *evaluated* twice in the first expression, once in the
    > > second.
    > >
    > > Robert Gamble

    >
    > *Evaluated * by the compiler? Or machine code?


    Evaluated by the abstract machine as per the C Standard.

    > Most compilers I know generate the same assembly in both cases, even with
    > optimisation turned off.


    An implementation does not have to evaluate part of an expression if
    the result of the expression can be deduced without doing so and if the
    program cannot tell the difference, irrespective of optimizations. In
    other words, x may be evaluated a _maximum_ of 2 times in the first
    expression and once in the second. It is therefore obviously possible
    that both operations result in x being evaluated the same number of
    times, namely one.

    Robert Gamble
    Robert Gamble, Nov 11, 2005
    #8
  9. Red Dragon

    Jordan Abel Guest

    On 2005-11-11, Robert Gamble <> wrote:
    > wrote:
    >> Robert Gamble wrote:
    >> > Jordan Abel wrote:
    >> > > On 2005-11-10, Robert Gamble <> wrote:
    >> > > > Red Dragon wrote:
    >> > > >> Can anybody tell me
    >> > > >> if x = x +1 is x++
    >> > > >
    >> > > > The effect may be equivalent but in the former x is evaluated twice
    >> > > > whereas in the latter x is evaluated once.
    >> > >
    >> > > actually, no. it's read once and modified once in both cases.
    >> >
    >> > As I said, x is *evaluated* twice in the first expression, once in the
    >> > second.
    >> >
    >> > Robert Gamble

    >>
    >> *Evaluated * by the compiler? Or machine code?

    >
    > Evaluated by the abstract machine as per the C Standard.
    >
    >> Most compilers I know generate the same assembly in both cases, even with
    >> optimisation turned off.

    >
    > An implementation does not have to evaluate part of an expression if
    > the result of the expression can be deduced without doing so and if the
    > program cannot tell the difference, irrespective of optimizations. In
    > other words, x may be evaluated a _maximum_ of 2 times in the first
    > expression and once in the second. It is therefore obviously possible
    > that both operations result in x being evaluated the same number of
    > times, namely one.
    >
    > Robert Gamble
    >


    The compiler can evaluate it as many or as few times as it pleases, as
    long as it acts "as if" it only did it as many times as you said. I take
    "evaluate" to mean "get the value of", and assigning to a variable does
    not "evaluate" it, it "assigns" it.
    Jordan Abel, Nov 11, 2005
    #9
  10. Jordan Abel wrote:
    > On 2005-11-11, Robert Gamble <> wrote:
    > > wrote:
    > >> Robert Gamble wrote:
    > >> > Jordan Abel wrote:
    > >> > > On 2005-11-10, Robert Gamble <> wrote:
    > >> > > > Red Dragon wrote:
    > >> > > >> Can anybody tell me
    > >> > > >> if x = x +1 is x++
    > >> > > >
    > >> > > > The effect may be equivalent but in the former x is evaluated twice
    > >> > > > whereas in the latter x is evaluated once.
    > >> > >
    > >> > > actually, no. it's read once and modified once in both cases.
    > >> >
    > >> > As I said, x is *evaluated* twice in the first expression, once in the
    > >> > second.
    > >> >
    > >> > Robert Gamble
    > >>
    > >> *Evaluated * by the compiler? Or machine code?

    > >
    > > Evaluated by the abstract machine as per the C Standard.
    > >
    > >> Most compilers I know generate the same assembly in both cases, even with
    > >> optimisation turned off.

    > >
    > > An implementation does not have to evaluate part of an expression if
    > > the result of the expression can be deduced without doing so and if the
    > > program cannot tell the difference, irrespective of optimizations. In
    > > other words, x may be evaluated a _maximum_ of 2 times in the first
    > > expression and once in the second. It is therefore obviously possible
    > > that both operations result in x being evaluated the same number of
    > > times, namely one.
    > >
    > > Robert Gamble
    > >

    >
    > The compiler can evaluate it as many or as few times as it pleases, as
    > long as it acts "as if" it only did it as many times as you said. I take
    > "evaluate" to mean "get the value of", and assigning to a variable does
    > not "evaluate" it, it "assigns" it.


    Well, you are wrong on both counts and it doesn't matter what you
    consider evaluate to mean. If you care to actually read what the
    Standard has to say you should start by reading the following
    paragraphs:

    5.1.2.3p3
    6.5.2.4p2
    6.5.16.2p3

    Robert Gamble.
    Robert Gamble, Nov 11, 2005
    #10
  11. On Fri, 11 Nov 2005 07:34:46 +0000 (UTC), in comp.lang.c , Jordan Abel
    <> wrote:

    >I take
    >"evaluate" to mean "get the value of", and assigning to a variable does
    >not "evaluate" it, it "assigns" it.


    In order to assign the value to a new variable, it has to evaluate the
    previous variable first. Computing isn't magic.

    --
    Mark McIntyre
    CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
    CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>

    ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
    http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
    ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
    Mark McIntyre, Nov 11, 2005
    #11
  12. Mark McIntyre <> writes:
    > On Fri, 11 Nov 2005 07:34:46 +0000 (UTC), in comp.lang.c , Jordan Abel
    > <> wrote:
    >
    >>I take
    >>"evaluate" to mean "get the value of", and assigning to a variable does
    >>not "evaluate" it, it "assigns" it.

    >
    > In order to assign the value to a new variable, it has to evaluate the
    > previous variable first. Computing isn't magic.


    Given

    x = y;

    y is evaluated, but x is not. (Specifically, the previous value of x
    is not evaluted.)

    --
    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.
    Keith Thompson, Nov 11, 2005
    #12
  13. On Fri, 11 Nov 2005 19:12:53 GMT, in comp.lang.c , Keith Thompson
    <> wrote:

    >Mark McIntyre <> writes:
    >> On Fri, 11 Nov 2005 07:34:46 +0000 (UTC), in comp.lang.c , Jordan Abel
    >> <> wrote:
    >>
    >>>I take
    >>>"evaluate" to mean "get the value of", and assigning to a variable does
    >>>not "evaluate" it, it "assigns" it.

    >>
    >> In order to assign the value to a new variable, it has to evaluate the
    >> previous variable first. Computing isn't magic.

    >
    >Given
    >
    > x = y;
    >
    >y is evaluated, but x is not. (Specifically, the previous value of x
    >is not evaluted.)


    I agree.
    --
    Mark McIntyre
    CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
    CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>

    ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
    http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
    ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
    Mark McIntyre, Nov 11, 2005
    #13
  14. Red Dragon

    Jordan Abel Guest

    On 2005-11-11, Mark McIntyre <> wrote:
    > On Fri, 11 Nov 2005 19:12:53 GMT, in comp.lang.c , Keith Thompson
    > <> wrote:
    >
    >>Mark McIntyre <> writes:
    >>> On Fri, 11 Nov 2005 07:34:46 +0000 (UTC), in comp.lang.c , Jordan Abel
    >>> <> wrote:
    >>>
    >>>>I take
    >>>>"evaluate" to mean "get the value of", and assigning to a variable does
    >>>>not "evaluate" it, it "assigns" it.
    >>>
    >>> In order to assign the value to a new variable, it has to evaluate the
    >>> previous variable first. Computing isn't magic.

    >>
    >>Given
    >>
    >> x = y;
    >>
    >>y is evaluated, but x is not. (Specifically, the previous value of x
    >>is not evaluted.)

    >
    > I agree.


    ....that's what i said. why's he right and i'm not?
    Jordan Abel, Nov 11, 2005
    #14
  15. Red Dragon

    SM Ryan Guest

    # >>Given
    # >>
    # >> x = y;
    # >>
    # >>y is evaluated, but x is not. (Specifically, the previous value of x
    # >>is not evaluted.)
    # >
    # > I agree.
    #
    # ...that's what i said. why's he right and i'm not?

    The lvalue x and rvalue y are evaluated.

    For example if an lvalue is a[i++], i will be incremented. Evaluation of
    an lvalue does not include loading whatever is at the address into a
    register or whatever.


    --
    SM Ryan http://www.rawbw.com/~wyrmwif/
    God's a skeeball fanatic.
    SM Ryan, Nov 11, 2005
    #15
  16. Red Dragon

    Tim Rentsch Guest

    Keith Thompson <> writes:

    > Mark McIntyre <> writes:
    > > On Fri, 11 Nov 2005 07:34:46 +0000 (UTC), in comp.lang.c , Jordan Abel
    > > <> wrote:
    > >
    > >>I take
    > >>"evaluate" to mean "get the value of", and assigning to a variable does
    > >>not "evaluate" it, it "assigns" it.

    > >
    > > In order to assign the value to a new variable, it has to evaluate the
    > > previous variable first. Computing isn't magic.

    >
    > Given
    >
    > x = y;
    >
    > y is evaluated, but x is not. (Specifically, the previous value of x
    > is not evaluted.)


    In the technical language of the Standard, I think it's more
    accurate to say that both x and y are evaluated, but only the
    evaluation of y results in a conversion of the lvalue to the
    value stored (which results in a read access of y's object).

    (In case someone wants a reference - try 6.3.2.1 p1,p2.)
    Tim Rentsch, Nov 11, 2005
    #16
  17. On Fri, 11 Nov 2005 23:08:02 +0000 (UTC), in comp.lang.c , Jordan Abel
    <> wrote:

    >>>> On Fri, 11 Nov 2005 07:34:46 +0000 (UTC), in comp.lang.c , Jordan Abel
    >>>> <> wrote:
    >>>>
    >>>>>I take
    >>>>>"evaluate" to mean "get the value of", and assigning to a variable does
    >>>>>not "evaluate" it, it "assigns" it.

    >
    >...that's what i said. why's he right and i'm not?


    Because it wasn't how what you wrote, read.

    Your words, quoted above, implied to me that assigning variable X to
    variable Y didn't evaluate X, it only assigned it. I believe we can
    agree that this is wrong.


    --
    Mark McIntyre
    CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
    CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>

    ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
    http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
    ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
    Mark McIntyre, Nov 12, 2005
    #17
  18. Red Dragon wrote:

    > Can anybody tell me
    > if x = x +1 is x++
    > What is x = x + 2 ?
    >


    x++; x++;


    Question: If the king sits on gold, who sits on silver???



    Answer: The Lone Ranger
    Charles Richmond, Nov 13, 2005
    #18
    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. =?Utf-8?B?dHJlbGxvdzQyMg==?=

    HELP! HELP! HELP! Opening Web Application Project Error

    =?Utf-8?B?dHJlbGxvdzQyMg==?=, Feb 20, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    735
    =?Utf-8?B?dHJlbGxvdzQyMg==?=
    Feb 20, 2004
  2. Harvey
    Replies:
    0
    Views:
    654
    Harvey
    Jul 16, 2004
  3. Harvey
    Replies:
    1
    Views:
    812
    Daniel
    Jul 16, 2004
  4. =?Utf-8?B?S2ltb24gSWZhbnRpZGlz?=

    HELP - HELP - HELP

    =?Utf-8?B?S2ltb24gSWZhbnRpZGlz?=, Mar 9, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    657
    Eliyahu Goldin
    Mar 9, 2006
  5. Buster

    Help, Help, Help

    Buster, Oct 4, 2003, in forum: Java
    Replies:
    3
    Views:
    457
    Saager
    Oct 30, 2003
Loading...

Share This Page