C Precedence question

Archives
Manoj Thakur

C Precedence question

Postby Manoj Thakur » Wed Mar 28, 2001 5:37 pm

Consider the following code snippet. What is the correct interpretation?<p><InitialState><br>p[0] = 11 &p[0] = 0x8000<br>p[1] = 22<br>p[2] = 33<br></InitialState><p><CodeSnippet><br>int v = *p + *p++ + *p + *p++ + *p;<br></CodeSnippet><p>What is the final value of "v, p and *p"?<p>The reason for the question is that it handled differently for HP-UX and Solaris, even though<br>I have exactly the same version of "gcc" to compile on the two platforms.
<br>
<br><hr size=7 width=75%><p>

naive

Re: C Precedence question

Postby naive » Fri Mar 11, 2005 2:16 pm

but 11 &amp; p[0] is not a Left Hand Side, is it?

Joe Carnuccio

Re: C Precedence question

Postby Joe Carnuccio » Thu Jun 29, 2006 9:28 pm

C specifies that the additions will NOT be done in left to right order (even though the precedence is left to right for addition);
addition is commutative, and the C &quot;spec&quot; allows each C implementation the freedom to exploit this.

Also, that line of code is very bad style because it relies on the order in which the additions are performed.


Return to “Archives”

Who is online

Users browsing this forum: No registered users and 1 guest