>One gets unexpected results if one does a string assignment of a short string from a longer string, vis:
Code: Select all
dim astring(12) as string
dim bstring(24) as string
bstring="Any string longer...1234"
astring=bstring
>to assume they're in contiguous memory)
>1)Does the BASIC kernel automatically re-allocate memory to astring?
>2)I would have expected either a run-time error or truncation. Am I wrong?
>3) does this cause a memory leak that might overwrite other variables?
There are NO runtime bounds checks on arrays or strings, few compilers insert that code. ARMbasic is a compiler and not an interpreter which many of those interpreters do add bounds checks.
So the bug in your code will show up as unexpected results, and it does not cause any kind of a memory leak. Variables are allocated at compile time and their location does not change during the code execution. This also includes SUB/FUNCTION parameters and variables which also have fixed allocation in the "heap".
Variables are allocated as encountered, INTEGER and SINGLE from the bottom, and ARRAYs and STRINGs from the top of the available space. Right above that area is the STRING accumulator and above that is the stack.