Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   effect of b = a++ + a++ (http://www.velocityreviews.com/forums/t585944-effect-of-b-a-a.html)

Ravi 01-20-2008 11:04 AM

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

Vimal Aravindashan 01-20-2008 11:33 AM

Re: effect of b = a++ + a++
 
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 01-21-2008 06:50 AM

Re: effect of b = a++ + a++
 

> 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 01-21-2008 07:02 AM

Re: effect of b = a++ + a++
 
On Mon, 21 Jan 2008 14:50:43 +0800,
friendfish <friendfish@gmail.com> 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 01-21-2008 07:14 AM

Re: effect of b = a++ + a++
 
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 01-21-2008 07:31 AM

Re: effect of b = a++ + a++
 
On Mon, 21 Jan 2008 01:14:07 -0600, Joachim Schmitz wrote
(in article <fn1go0$8qu$1@online.de>):

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



--
Randy Howard (2reply remove FOOBAR)
"The power of accurate observation is called cynicism by those
who have not got it." - George Bernard Shaw






Kaz Kylheku 01-21-2008 08:15 AM

Re: effect of b = a++ + a++
 
On Jan 20, 3:04*am, Ravi <ra.ravi....@gmail.com> 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
unable to read the FAQ or operate the Google search engine.


Martin Ambuhl 01-21-2008 08:24 AM

Re: effect of b = a++ + a++
 
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 01-21-2008 08:07 PM

Re: effect of b = a++ + a++
 
On Jan 20, 10:50*pm, friendfish <friendf...@gmail.com> 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;


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.

CBFalconer 01-21-2008 11:27 PM

Re: effect of b = a++ + a++
 
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>
Try the download section.



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



All times are GMT. The time now is 12:32 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.