Also, would anybody happen to know how exactly integer identifiers are assigned to structs?
JASS:struct a endstruct
JASS:constant integer si__a=1 integer si__a_F=0 integer si__a_I=0 integer array si__a_V //Generated allocator of a function s__a__allocate takes nothing returns integer local integer this=si__a_F //first node on recycle stack if (this!=0) then set si__a_F=si__a_V[this] //set stack to next node (like stack.next) else set si__a_I=si__a_I+1 set this=si__a_I endif if (this>8190) then //protection against too many structs return 0 endif set si__a_V[this]=-1 //set stack to -1 (stack.next = -1) return this endfunction //Generated destructor of a function s__a_deallocate takes integer this returns nothing if this==null then //don't deallocate null instance return elseif (si__a_V[this]!=-1) then //double free protection return endif set si__a_V[this]=si__a_F //set this.next = stack set si__a_F=this //set stack = this endfunction
Can vJass structs have integer value 0?
struct Test
integer x
endstruct
struct Tester extends array
static integer array r
static integer m = 0
static method allocate takes nothing returns thistype
local thistype this
if r[0]==0 then
set this=m
set m=m+1
else
set this=r[0]
set r[0]=r[r[0]]
endif
return this
endmethod
method deallocate takes nothing returns nothing
set r[this]=r[0]
set r[0]=this
endmethod
endstruct
Yes you can, the only thing an array struct is different from a non array struct are the default allocation methods and the fact that you can't extend a struct to an array struct (which is really stupid)It's not going to compile, since you can't use arrays inside array structs.
If 0 isn't null, how do you check if a struct variable is null or not?.
In a linked list, how do you check when node.next or node.prev are null?
Always make 0 null and start your struct instances at 1.
That extra 1 instance isn't important. Just stick to using 0 as null!I guess you are referring to the default values of Wc3, game caches, hash tables and integer arrays returning 0 at unassigned keys.
Integers are 0 by default, not -1. Using 0 as null means structs are null as default, and not whichever random instance happens to be the first one. Also this:
That extra 1 instance isn't important. Just stick to using 0 as null!