What do you think the following C should do?
In both of these cases, the code looks sane. The compiler doesn't flag them as errors. But the results aren't what you'd expect.
unsigned byte zmem[128*1024];
int read_word( int a, x )
{
a = zmem[a++]<<8 + zmem[a];
...
}
There are three (!) errors in the above code:- precedence error : addition is done before shift
- order of operations : is a incremented before the second array reference?
- compiler bug : a contains a++ after the operation
int PC;
void run( void )
{
...
op2code( op & 31, zmem[PC++], zmem[PC++] );
...
}
Looks reasonable, provide the next two bytes in the instruction stream as operands. Again, there are several potential bugs lurking:- is PC incremented before or after the function call (tested - it's before, at least with my compiler)
- order of operations : which operand gets which byte?
- is actually PC incremented before the second array reference?
In both of these cases, the code looks sane. The compiler doesn't flag them as errors. But the results aren't what you'd expect.



Create a custom theme








