Forum
Error: -1 - Printable Version

+- Forum (https://www.boriel.com/forum)
+-- Forum: Compilers and Computer Languages (https://www.boriel.com/forum/forumdisplay.php?fid=12)
+--- Forum: ZX Basic Compiler (https://www.boriel.com/forum/forumdisplay.php?fid=11)
+---- Forum: Bug Reports (https://www.boriel.com/forum/forumdisplay.php?fid=15)
+---- Thread: Error: -1 (/showthread.php?tid=2555)



Error: -1 - zarsoft - 08-06-2024

DIM s AS STRING
s = ""
PRINT LEN s-1 ' gives 65535
PRINT LEN ""-1 ' gives -1


RE: Error: -1 - boriel - 08-10-2024

That's a casting problem (inconsistency).
LEN (string) is of type UInteger, so 65535 makes sense.
The second statement, LEN "" is being evaluated to 0 in compile time, hence converted to Integer (Do you get a Warning with these?)

I will have a look into it, however.

If you want to ensure you get -1, use Cast(Integer, LEN s) to ensure it's always Integer (-32768 to 32767).