When I run this program in a usual way (nim c -r), it stops with overflow error. How can I switch this check inside? I tried what I could find in doc/sources, but it does not seem to work.
{.push overflowChecks: off.}
proc `^`(x,y:int):int = (var r=1;for i in 1..y:r*=x;r)
echo BiggestInt.high # 9223372036854775807
echo ((var s=0;for i in 0..62:s+=2^i;s)) # 9223372036854775807
echo 2^63-1 # overflow unless -d:release
#[
Traceback (most recent call last)
power.nim(7) power
power.nim(2) ^
system.nim(3529) *=
system.nim(2724) sysFatal
Error: unhandled exception: over- or underflow [OverflowError]
Error: execution of an external program failed: 'D:\blah-blah\power.exe '
]#
{.pop.}
Of course, nim c -r -d:release power.nim shows no such error, just three the same numbers.
Ah, I've found where the bug is.
If it's written there as r = r * x, it's compiled into r = (NI)(r * x); and it's ok.
But if it's written as r *= x, it's compiled into stareq__blah-blah((&r), x); which obviously ignores that pragma. So it must have been like r *= x; in C code instead of stareq....