Velocity Reviews > Help

# Help

Red Dragon
Guest
Posts: n/a

 11-10-2005
Can anybody tell me
if x = x +1 is x++
What is x = x + 2 ?

Thanks
Khoon.

Giovanni
Guest
Posts: n/a

 11-10-2005
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/>

Robert Gamble
Guest
Posts: n/a

 11-10-2005
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

Jordan Abel
Guest
Posts: n/a

 11-10-2005
On 2005-11-10, Robert Gamble <(E-Mail Removed)> 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.

Red Dragon
Guest
Posts: n/a

 11-10-2005
>>> 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.

Robert Gamble
Guest
Posts: n/a

 11-11-2005
Jordan Abel wrote:
> On 2005-11-10, Robert Gamble <(E-Mail Removed)> 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

slebetman@yahoo.com
Guest
Posts: n/a

 11-11-2005
Robert Gamble wrote:
> Jordan Abel wrote:
> > On 2005-11-10, Robert Gamble <(E-Mail Removed)> 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.

Robert Gamble
Guest
Posts: n/a

 11-11-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Robert Gamble wrote:
> > Jordan Abel wrote:
> > > On 2005-11-10, Robert Gamble <(E-Mail Removed)> 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

Jordan Abel
Guest
Posts: n/a

 11-11-2005
On 2005-11-11, Robert Gamble <(E-Mail Removed)> wrote:
> (E-Mail Removed) wrote:
>> Robert Gamble wrote:
>> > Jordan Abel wrote:
>> > > On 2005-11-10, Robert Gamble <(E-Mail Removed)> 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.

Robert Gamble
Guest
Posts: n/a

 11-11-2005
Jordan Abel wrote:
> On 2005-11-11, Robert Gamble <(E-Mail Removed)> wrote:
> > (E-Mail Removed) wrote:
> >> Robert Gamble wrote:
> >> > Jordan Abel wrote:
> >> > > On 2005-11-10, Robert Gamble <(E-Mail Removed)> 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.