[patch] Bug #459

Aaron Lehmann (aaronl@vitelus.com)
Fri, 18 Jun 1999 06:33:40 +0000 ( )


I summerized the description of the metrowerks problem and added it to the
programmer guidelines. here's the patch:

--- abi.vanilla/docs/AbiSource_ProgrammerGuidelines.abw Thu Jun 17 22:47:36 1999
+++ abi/docs/AbiSource_ProgrammerGuidelines.abw Thu Jun 17 23:26:42 1999
@@ -59,6 +59,21 @@
<p></p>
<p>17. Don't break the tree. This is a Big One. Some Open Source projects seem to be very forgiving about checking in code which doesn't compile or causes instant crashes. We're not. Around here, when someone breaks the tree, we require them to buy donuts.</p>
<p></p>
+<p>18. Don't declare variables in the declaration of a 'for' loop of 'if' conditional and expect them to work outside the scope of the block of code. A bug in Metrowerks CodeWarrior causes such variables to be restricted to the scope of the conditional or loop. For example, this is perfectly legal C++:</p>
+<p></p>
+<p><c props="font-family:Courier New; font-size:9pt">for (int i=0; i &gt; 10; i++) {</c></p>
+<p><c props="font-family:Courier New; font-size:9pt"> printf("i is %d \n", i);</c></p>
+<p><c props="font-family:Courier New; font-size:9pt">}</c></p>
+<p><c props="font-family:Courier New; font-size:9pt">printf("I is now %d \n", i);</c></p>
+<p></p>
+<p>CodeWarrior will refuse to compile it because 'i' is used after the for loop. To avoid this bug, use code like this:</p>
+<p></p>
+<p><c props="font-family:Courier New; font-size:9pt; font-style:normal; font-weight:normal; text-decoration:none">int i;</c></p>
+<p><c props="font-family:Courier New; font-size:9pt; font-style:normal; font-weight:normal; text-decoration:none">for (i=0; i &gt; 10; i++) {</c></p>
+<p><c props="font-family:Courier New; font-size:9pt; font-style:normal; font-weight:normal; text-decoration:none"> printf("I is %d \n", i);</c></p>
+<p><c props="font-family:Courier New; font-size:9pt; font-style:normal; font-weight:normal; text-decoration:none">}</c></p>
+<p><c props="font-family:Courier New; font-size:9pt; font-style:normal; font-weight:normal; text-decoration:none">printf("i is now %d \n", i);</c></p>
+<p></p>
+<p>in the xp/library code.</p>
</section>
</abiword>



This archive was generated by hypermail 1.03b2.