effect of b = a++ + a++

M

Martien Verbruggen

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
 
R

Randy Howard

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

Kaz Kylheku

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
unable to read the FAQ or operate the Google search engine.
 
M

Martin Ambuhl

friendfish said:
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.
 
K

Kaz Kylheku

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

Please don't answer questions in the newsgroup if you haven't read and
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.
 
C

CBFalconer

friendfish said:
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).
 
S

santosh

MisterE said:
news:5419df4d-848a-441c-b02f-0f16b7dfd974@i72g2000hsd.googlegroups.com...

just do b=a+a; a+=2; and stop being a **** head

Neither will do what the OP's code does, simply because the OP code is
undefined.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top