is this a valid error
billcollis opened this issue · comments
Felix, not sure if this should flag an error or not.
#include
using namespace std;
int main() {
unsigned char a = 23;
a << 4;
return a;
}
returns 5:5 overflow of 368(unsigned char)
I am using this as a C simulator, where I would expect it to just do the shift and loose the bits and not create an error.
I guess I could modify CRuntime::val in rt.coffee to change this behaviour
thanks
What I have done is added the following function
CRuntime::fixoverunderrange = (type, value) ->
limit = @config.limits[type.name]
if @isPrimitiveType(type)
while value > limit.max
value -= limit.max
value--
while value < limit.min
value += limit.max
value++
return value
and changed
if @isNumericType(type) and not @inrange(type, v)
v=@fixoverunderrange(type, v)
Yeah ideally such behaviors should be configurable. Glad that you found a solution on your own.