In the following script as part of the output, I get: =-2147483648+312704 Invalid Number. Numbers are limited to 32-bits of precision.
This is obviously within the bounds of a signed 32-bit number (I also tried 2147483648+312704 thinking that only unsigned 32 is supported), but got the same error.
Oddly enough, this script works fine on WindowsXP, but when I try it on Windows7, I get the above error.
Why won't batch perform this operation?
For convenience the code is below...
setlocal EnableDelayedExpansion
@set TEMPDIR="%CD%\temp739123834543"
@set ADDR=-2147483648
@set HEXADDR=
@set /a ZIPSLEEP_MS=0
@del frontScreenImages.c
@del frontScreen.zip
@mkdir %TEMPDIR%
for %%f in (*.png) do (
echo %%~nf
@call toHex ADDR HEXADDR
echo "ADDR:!HEXADDR!"
convertFrontScreenPng.exe %%~nf.png frontScreenImages.c transpose append "0x!HEXADDR!" "__xdata_rom" "#pragma required="
rem set BINFILE=%TEMPDIR%\a!HEXADDR!_%%~nf.bin
set BINFILE=%TEMPDIR%\a80000000_frontScreenImages.bin
echo "BIN:!BINFILE!"
convertFrontScreenPng.exe %%~nf.png !BINFILE! transpose append
for %%A in (!BINFILE!) do set /a ADDR=%ADDR%+%%~zA
set /a ZIPSLEEP_MS=!ZIPSLEEP_MS! + 500
)
@echo Set objArgs = WScript.Arguments > _zipIt.vbs
@echo InputFolder = objArgs(0) >> _zipIt.vbs
@echo ZipFile = objArgs(1) >> _zipIt.vbs
@echo CreateObject("Scripting.FileSystemObject").CreateTextFile(ZipFile, True).Write "PK" ^& Chr(5) ^& Chr(6) ^& String(18, vbNullChar) >> _zipIt.vbs
@echo Set objShell = CreateObject("Shell.Application") >> _zipIt.vbs
@echo Set source = objShell.NameSpace(InputFolder).Items >> _zipIt.vbs
@echo objShell.NameSpace(ZipFile).CopyHere(source) >> _zipIt.vbs
@echo wScript.Sleep !ZIPSLEEP_MS! >> _zipIt.vbs
@CScript _zipIt.vbs %TEMPDIR% "%CD%\frontScreen.zip"
@del _zipIt.vbs
@rmdir %TEMPDIR% /s /q
sleep 3
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.