Re:Writing a register based VM in less than 125 lines of C code
by Joker_vD on Thursday December 09, 2021 @08:19AM
(#29496993)
A language lawyer quiz: if the definition is changed to
is it guaranteed to work on platforms where unsigned int is 16-bit wide? What about platforms where void* is 16-bit wide (hint: &mem[65536] must be a valid pointer value that must compare unequal from &mem[0])?
[ Parent
| on HN ]
Re:Writing a register based VM in less than 125 lines of C code
by im3w1l on Thursday December 09, 2021 @09:18AM
(#29497570)
> &mem[65536] must be a valid pointer value
explain
Re:Writing a register based VM in less than 125 lines of C code
by Joker_vD on Thursday December 09, 2021 @09:47AM
(#29497883)
C99 draft, 6.5.6.8:
Moreover, if the expression P points to the last element of an array object,
the expression (P)+1 points one past the last element of the array object,
and if the expression Q points one past the last element of an array object,
the expression (Q)-1 points to the last element of the array object. If both
the pointer operand and the result point to elements of the same array object,
or one past the last element of the array object, the evaluation shall not
produce an overflow; otherwise, the behavior is undefined. If the result points
one past the last element of the array object, it shall not be used as the
operand of a unary * operator that is evaluated.