Explain var declarations to me...
mre_rob
Posts: 31
When you declare a var as a byte, is that really just a way to say that the var starts at this memory location? I can see no way to define how many bytes the var should allocate. I discovered this during a byte parsing issue. Once I defined the var as an array of bytes, my overrun problem went away. I thought I read about var declarations in the spin manual, but maybe I missed this fact. Or is it assumed that since this is a low level language, most things are just pointers.
Also, are params passed into methods by reference or by value?
Is there a way to define a byte array var within the scope of a method? I am looking to isolate code, but I was not able to define byte arrays within the scope of a method.
My last one.... when should you use Dat vs. Var?
thanks...
Also, are params passed into methods by reference or by value?
Is there a way to define a byte array var within the scope of a method? I am looking to isolate code, but I was not able to define byte arrays within the scope of a method.
My last one.... when should you use Dat vs. Var?
thanks...
Comments
2) Parameters are passed by value
3) There's no way to define a byte array as a local variable since all local variables are long words (32-bit). There is a way to override the access to the local variable by using a ".WORD" or ".BYTE" suffix and you can follow this with an array subscript if you want. If you declare a local variable "X" as an array of 4 long words, you can use the area as a 16 byte array like "x.byte[noparse][[/noparse] i ]".
4) VAR variables are allocated once for each instance of an object. DAT space is allocated only once for all instances. You'd put a variable into a DAT section if it is to be shared among all the instances of the object. If an object has only one instance, then it doesn't much matter where you put it although you can initialize a variable declared as a DAT. All VAR variables are initialized to zero when the program is loaded.