Example code:
struct MyStruct
{
import static int func();
};
function SomeOtherFunc()
{
int arr[100];
int var = arr[MyStruct.func()]; // <--- line X
}
Compiler stops with error: " Error (line X): parse error after '[' ".
Possible workaround:
int dummy = MyStruct.func();
int var = arr[dummy];
I didn't test this and the error seems unrelated, but doesn't an array declaration require a constant?
What happens if you try this using a dynamic array?
Quote from: Khris on Thu 08/07/2010 18:51:18
I didn't test this and the error seems unrelated, but doesn't an array declaration require a constant?
What happens if you try this using a dynamic array?
It isn't array declaration. It is getting array's element by index.
There's no error if a non-static struct member is used.
I guess it is parsing mistake.
Yeah, I've noticed that the compiler sometimes doesn't really like complex expressions between the square brackets of an array.
The few times it happend, as you already mentionned, I used the workaround to use a temporary variable :
temporary variable : = complex expression
array[temporary variable] : = ...
Yeah, sorry, I have to stop posting here while being too tired =)
Quote from: Monsieur OUXX on Fri 09/07/2010 11:03:28
temporary variable : = complex expression
array[temporary variable] : = ...
Pascal coder detected ;D
Yes, there are a couple of limitations on the way the compiler handles static functions & properties. It's the same reason that this doesn't work:
int hour = DateTime.Now.Hour;
I will try to get around to fixing it at some point.