Velocity Reviews > effect of b = a++ + a++

# effect of b = a++ + a++

Ravi
Guest
Posts: n/a

 01-20-2008
what is the effect of fllowing code n values of a and b
b = 0;
a = 1;
b = a++ + a++;

Vimal Aravindashan
Guest
Posts: n/a

 01-20-2008
Ravi wrote:
> what is the effect of fllowing code n values of a and b
> b = 0;
> a = 1;
> b = a++ + a++;

Please refer to section 3 (Expressions) of the FAQ. Here is a link to
the same: http://www.c-faq.com/expr/index.html.

Regards,
Vi

friendfish
Guest
Posts: n/a

 01-21-2008

> what is the effect of fllowing code n values of a and b
> b = 0;
> a = 1;
> b = a++ + a++;

That is "(b= (a++)+(a++))", after that b=2 and a=3;

Martien Verbruggen
Guest
Posts: n/a

 01-21-2008
On Mon, 21 Jan 2008 14:50:43 +0800,
friendfish <(E-Mail Removed)> wrote:
>
>> what is the effect of fllowing code n values of a and b
>> b = 0;
>> a = 1;
>> b = a++ + a++;

> That is "(b= (a++)+(a++))", after that b=2 and a=3;

Neither the C standard or the FAQ agree with you.

Maybe on your particular compiler it works like that, but you have no
guarantee that it will work like that anywhere else.

See another post in this same thread for a reference to the C FAQ that
explains why you should not do this.

Martien
--
|
Martien Verbruggen | Louis Pasteur's theory of germs is ridiculous
| fiction -- Pierre Pachet, Professor of
| Physiology at Toulouse, 1872

Joachim Schmitz
Guest
Posts: n/a

 01-21-2008
friendfish wrote:
>> what is the effect of fllowing code n values of a and b
>> b = 0;
>> a = 1;
>> b = a++ + a++;

> That is "(b= (a++)+(a++))", after that b=2 and a=3;

Not neccessarily. Read the FAQs as mentioned by a previous poster.

Bye, Jojo

Randy Howard
Guest
Posts: n/a

 01-21-2008
On Mon, 21 Jan 2008 01:14:07 -0600, Joachim Schmitz wrote
(in article <fn1go0\$8qu\$(E-Mail Removed)>):

> friendfish wrote:
>>> what is the effect of fllowing code n values of a and b
>>> b = 0;
>>> a = 1;
>>> b = a++ + a++;

>> That is "(b= (a++)+(a++))", after that b=2 and a=3;

> Not neccessarily. Read the FAQs as mentioned by a previous poster.
>

I get this from the compiler:
b.c: In function mainš:
ub.c:10: warning: operation on aš may be undefined

'May' being an interesting spin on things.

--
"The power of accurate observation is called cynicism by those
who have not got it." - George Bernard Shaw

Kaz Kylheku
Guest
Posts: n/a

 01-21-2008
On Jan 20, 3:04*am, Ravi <(E-Mail Removed)> wrote:
> what is the effect of fllowing code n values of a and b
> b = 0;
> a = 1;
> b = a++ + a++;

The effect is that it stupefies the reader to the point that he's

Martin Ambuhl
Guest
Posts: n/a

 01-21-2008
friendfish wrote:
>
>> what is the effect of fllowing code n values of a and b
>> b = 0;
>> a = 1;
>> b = a++ + a++;

> That is "(b= (a++)+(a++))", after that b=2 and a=3;

No, after that the value of b is undefined. Please learn about sequence
points.

This is yet another example of a tiresome error adequately discussed in
the FAQ. Unfortunately, the same people that "know" what this
ill-formed code means are the same ones who won't bother reading the FAQ
or following the newsgroup before posting.

Kaz Kylheku
Guest
Posts: n/a

 01-21-2008
On Jan 20, 10:50*pm, friendfish <(E-Mail Removed)> wrote:
> > what is the effect of fllowing code n values of a and b
> > b = 0;
> > a = 1;
> > b = a++ + a++;

>
> That is "(b= (a++)+(a++))", after that b=2 and a=3;

understood the FAQ.

You look like an ignorant ass who doesn't know anything, and can't be
bothered to do as little as three minutes of basic research before
submitting an article.

CBFalconer
Guest
Posts: n/a

 01-21-2008
friendfish wrote:
>
>> what is the effect of fllowing code n values of a and b
>> b = 0;
>> a = 1;
>> b = a++ + a++;

>
> That is "(b= (a++)+(a++))", after that b=2 and a=3;

No. The only effect is undefined behaviour. Anything at all can
happen. You could find yourself 6 mos. pregnant (although the
likelihood is probably low).

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>

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