No: the issue is when you assign to a. You can always do something like int b=a/3+(a*4)-a; but when you use ++a your assigning/changing.
----- Original Message ----- From: Michael White To: c-prog@yahoogroups.com Sent: Thursday, July 16, 2009 1:39 PM Subject: Re: [c-prog] I am not agree with u. Oh, so you're saying that it should be done more like.... int a; a = 6 / (++a); ...? --- On Thu, 7/16/09, Brett McCoy <idragos...@gmail.com> wrote: From: Brett McCoy <idragos...@gmail.com> Subject: Re: [c-prog] I am not agree with u. To: c-prog@yahoogroups.com Date: Thursday, July 16, 2009, 2:33 PM On Thu, Jul 16, 2009 at 3:08 PM, Michael White<michael_whi...@yahoo.com> wrote: > Which compiler are you using? > > Every compiler I know reads within ( ) first, and then from right to the left. The only time the code I present would have a problem was if the 'a' was a zero (0), because it will crash if you try to divide anything by '0'. This is the special case where the same variable is accessed (both read and write, in this case) multiple times between sequence points. That's undefined behavior for the language. The solution is to simplify things so there's no ambiguity like this -- break it into multiple statements. > --- On Thu, 7/16/09, Paul Herring <pauljherr...@gmail.com> wrote: > > From: Paul Herring <pauljherr...@gmail.com> > Subject: Re: [c-prog] I am not agree with u. > To: c-prog@yahoogroups.com > Date: Thursday, July 16, 2009, 2:04 PM > > On Thu, Jul 16, 2009 at 4:54 PM, Michael White<michael_whi...@yahoo.com> wrote: >> A way to help determine how you want the following scenario to play out >> is to surround the piece of code you want to be sure is enacted on first with ( ). >> >> For example... >> >> int b = a / (++a); >> >> This will remove all doubt as to what will happen. > > No it won't. Adding parenthesis does absolutely nothing in this situation. > > It's still invalid code, because either the numerator or denominator > can be examined first, leading to two different possible answers. > > -- > PJH > > http://shabbleland.myminicity.com/com > http://www.chavgangs.com/register.php?referer=9375 > > > ------------------------------------ > > To unsubscribe, send a blank message to <mailto:c-prog-unsubscr...@yahoogroups.com>.Yahoo! Groups Links > > > > > > [Non-text portions of this message have been removed] > > > > ------------------------------------ > > To unsubscribe, send a blank message to <mailto:c-prog-unsubscr...@yahoogroups.com>.Yahoo! Groups Links > > > > -- ---------------------------------------------------------- "In the rhythm of music a secret is hidden; If I were to divulge it, it would overturn the world." -- Jelaleddin Rumi ------------------------------------ To unsubscribe, send a blank message to <mailto:c-prog-unsubscr...@yahoogroups.com>.Yahoo! Groups Links [Non-text portions of this message have been removed] [Non-text portions of this message have been removed]