Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BCC allows to access multi-dim arrays with less/more dimensions #649

Open
GWRon opened this issue Jan 11, 2024 · 1 comment
Open

BCC allows to access multi-dim arrays with less/more dimensions #649

GWRon opened this issue Jan 11, 2024 · 1 comment

Comments

@GWRon
Copy link
Contributor

GWRon commented Jan 11, 2024

@MidimasterSoft wrote at discord:

There was a question on SyntaxBomb about arrays. During the answer I found out, that this wrong code line does not raise an error message in BlitzMax NG DEBUG and RELEASE mode:

Global Test:Int[1, 1, 2]
 
' now call the array with one dimension too small, but no error message:
Test[0,0]=4

Print Test[0,0,0] + " " + Test[0,0,1]

I asked for the output of vanilla:

Building untitled1
Compiling:test.bmx
Compile Error: Incorrect number of array dimensions
[C:/code/test.bmx;4;1]
Build Error: failed to compile C:/code/test.bmx
Process complete

Maybe bcc could spit out a similar error (maybe even with "given vs required")

@GWRon
Copy link
Contributor Author

GWRon commented Jan 16, 2024

The generated code indicates that the C code uses "1 dimensional arrays" and simply adds up the passed indices of the multi-dimensional access to a single index.

Local int_array:Int[1,1,2]
int_array[0,0] = 4
int_array[1,0,0] = 4

becomes

		BBARRAY bbt_int_array=bbArrayNew("i", 3, 1, 1, 2);
		BBUINT* bbt_=((BBARRAY)bbt_int_array)->scales + 1;
		((BBINT*)BBARRAYDATA(bbt_int_array,1))[(*(bbt_)) * 0U + 0U]=4;
		BBUINT* bbt_2=((BBARRAY)bbt_int_array)->scales + 1;
		((BBINT*)BBARRAYDATA(bbt_int_array,1))[(*(bbt_2)) * 1U + (*(bbt_2+1)) * 0U + 0U]=4;

Does not help much though -- regarding the BCC checks, but explains why it is "working" (as long as you just leave out dimensions / aka setting their index indirectly to "0")

@GWRon GWRon changed the title BCC allows to access multi-dim arrays with less dimensions BCC allows to access multi-dim arrays with less/more dimensions Jan 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant