Read-only archive of the Armageddon Games Forums Archive (2000–2026) · About this archive

SizeOfArray() issue

1 replies · 5,491 views · Started 05 January 2015

I tried doing this:
[PHP]int var = 1;
if(SizeOfArray(var)==-1)
Link->Item[I_SWORD1];
[/PHP]

Worked just find, except that it traced an error message in allegro.log saying that it tried to pass the value of var as an index into the array; returns -1 regardless of what number you put in as it should since it's not an array.

There's no way to make it work. If you modify your code as follows:

int arr[5];
int var = 1;
if(SizeOfArray(var)==-1)
Link->Item[I_SWORD1];

you'll find that SizeOfArray(var) is 5, because arr==var (assuming there weren't any other arrays already). An array pointer is just a number, so an arbitrary number may well be a valid array pointer. There isn't a way we could distinguish between arrays and numbers without fundamental changes to the language.