I repeat the answers of David Ruhmann and Endoro with some extra information.
It is explained at Rules for how CMD.EXE parses numbers why value -2147483648
results in an invalid number error message on parsing the number on Windows Vista, Windows 7 and perhaps also Windows 8 while there is no problem on Windows XP. The code for string to signed/unsigned int conversion is written poorly in source code of cmd.exe
and therefore not working right for minimum signed 32-bit integer number.
One solution for this batch file is using
set /a ADDR+=%%~zA
instead of
set /a ADDR=%ADDR%+%%~zA
as this results in the command line
set /a ADDR+=312704
instead of
set /a ADDR=-2147483648+312704
But that is not the only solution for
@echo off
set VALUE1=-2147483648
set VALUE2=312704
set /a RESULT=%VALUE1%+%VALUE2%
echo Result of %VALUE1% + %VALUE2% is %RESULT%
resulting in an error message on execution on Windows 7 and Vista.
Another solution is what most limits.h
for C/C++ contain for INT_MIN preprocessor macro to avoid same problem on poorly coded preprocessors: the definition of minimum signed 32-bit integer number as expression instead of fixed value.
#define INT_MIN (-2147483647-1)
#define LONG_MIN (-2147483647L-1L)
This workaround solution applied to the small batch file from above:
@echo off
set VALUE1=(-2147483647-1)
set VALUE2=312704
set /a RESULT=%VALUE1%+%VALUE2%
echo Result of %VALUE1% + %VALUE2% is %RESULT%
Now there is no problem on execution of the batch file even on Windows 7 and Vista.