Page 1 of 1

Byte Array inside Structure Error

Posted: Tue Jun 28, 2011 5:11 pm
by Mr52
Structure GENERALINPUT
dwType .l
xi.b(23)
EndStructure

When i enter this i get

---------------------------
PureBasic
---------------------------
Line 3: Garbage at the end of the line.
---------------------------
OK
---------------------------


Please tell me why

Re: Byte Array inside Structure Error

Posted: Tue Jun 28, 2011 5:12 pm
by skywalk
Add... Array xi.b(23)

Re: Byte Array inside Structure Error

Posted: Tue Jun 28, 2011 5:12 pm
by STARGĂ…TE

Code: Select all

Structure GENERALINPUT
	dwType .l
	xi.b[24]
EndStructure
or

Code: Select all

Structure GENERALINPUT
	dwType .l
	Array xi.b(23)
EndStructure

Re: Byte Array inside Structure Error

Posted: Tue Jun 28, 2011 5:15 pm
by Mr52
wow thank you didnt know PB has Array as keyword :P

Re: Byte Array inside Structure Error

Posted: Tue Jun 28, 2011 6:33 pm
by helpy
Differences between the two ways of defining arrays in Structures:

Code: Select all

Structure GENERALINPUT1
	dwType .l
	xi.b[24]
EndStructure
Structure GENERALINPUT2
	dwType .l
	Array xi.b(23)
EndStructure

Debug SizeOf(GENERALINPUT1)
Debug SizeOf(GENERALINPUT2)
The first is an static array, which you can not resize! The byte array is part of the structure (see size of structure)

The second one is an dynamic array, which you can resize. The structure only contains an pointer to the array!

Maybe others can add more information and differences!

cu,
guido

Re: Byte Array inside Structure Error

Posted: Tue Jun 28, 2011 10:05 pm
by netmaestro
The first is an static array, which you can not resize! The byte array is part of the structure (see size of structure)
Not exactly true. If you put zero in the brackets you have a completely dynamic array, any size you like, which can be accessed by index as long as the memory it points to is valid. A small example:

Code: Select all

Structure stuff
  char.b[0]
EndStructure

a$ = "start"+Space(50000)+"end"
*char.stuff = AllocateMemory(50009)
PokeS(*char, a$)

Debug Chr(*char\char[50005])+Chr(*char\char[50006])+Chr(*char\char[50007])
The purifier is perfectly happy with this code. Of course, if you put anything greater than zero in, you can't go past the boundary. In that case, it's static and un-resizeable.