In this post I found out that it seems to be no problem using a size of -1 for Dim or ReDim.
Example with Dim:
Code: Select all
Define size.i = -1
Dim arr.i(size)
Debug ArraySize(arr())
Code: Select all
Dim arr.i(0)
Debug ArraySize(arr())
Define size.i = -1
ReDim arr(size)
Debug ArraySize(arr())
Code: Select all
Define size.i = -1
Dim arr.i(size)
Debug ArraySize(arr())
ReDim arr(0) ; --> Invalid memory access
Debug ArraySize(arr())
So I think at first look it is a bug that you can set the size to -1 and even ArraySize() reports the size as -1. And of course it is a bug that increasing the size results in an invalid memory access. But on the other hand it is very helpful when working with JSON and you don't want to program in special cases for empty arrays.
Let's discuss together if this should be moved to the Bug forum.
I tested it with PureBasic 6.20 (x64) on Ubuntu 24.04.