Gotchas: Difference between revisions
Content added Content deleted
Puppydrum64 (talk | contribs) |
Puppydrum64 (talk | contribs) No edit summary |
||
Line 159: | Line 159: | ||
EXT.L D1 ;D1 = $FFFF8000</syntaxhighlight> |
EXT.L D1 ;D1 = $FFFF8000</syntaxhighlight> |
||
=={{header| |
=={{header|C}}== |
||
=== |
===if(a=b)=== |
||
This is an easy mistake to make if you're in a hurry. The ''assignment operator'' <code>=</code> is different from the ''equality comparison operator'' <code>==</code>. Therefore you have the following similar looking but vastly different statements, both of which are valid. |
|||
⚫ | |||
<syntaxhighlight lang=" |
<syntaxhighlight lang="C">if(a=b){} //assigns to "a" the value of "b". Then, if "a" is nonzero, the code in the curly braces is run. |
||
⚫ | |||
⚫ | |||
if(a==b){} //runs the code in the curly braces if and only if the value of "a" equals the value of "b".</syntaxhighlight> |
|||
⚫ | Now, you may think that the 1 gets added first and therefore the branch doesn't take place since the conditions are no longer true. However, this is '''not the case.''' The condition is already "locked in" by the time <code>addiu $t0,1</code> finishes. If you compared again immediately upon arriving at <code>myLabel</code>, the condition would be false. |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
=={{header|J}}== |
=={{header|J}}== |
||
Line 295: | Line 283: | ||
</pre> |
</pre> |
||
=={{header|MIPS Assembly}}== |
|||
===Delay Slots=== |
|||
⚫ | |||
<syntaxhighlight lang="mips">move $t0,$zero ;load 0 into $t0 |
|||
⚫ | |||
⚫ | |||
⚫ | Now, you may think that the 1 gets added first and therefore the branch doesn't take place since the conditions are no longer true. However, this is '''not the case.''' The condition is already "locked in" by the time <code>addiu $t0,1</code> finishes. If you compared again immediately upon arriving at <code>myLabel</code>, the condition would be false. |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
Perl has lists (which are data, and ephemeral) and arrays (which are data structures, and persistent), distinct entities but tending to be thought of as inter-changable. Combine this with the idea of <i>context</i>, which can be 'scalar' or 'list', and the results might not be as expected. Consider the handling of results from a subroutine, in a scalar context: |
Perl has lists (which are data, and ephemeral) and arrays (which are data structures, and persistent), distinct entities but tending to be thought of as inter-changable. Combine this with the idea of <i>context</i>, which can be 'scalar' or 'list', and the results might not be as expected. Consider the handling of results from a subroutine, in a scalar context: |