Byte Array inside Structure Error

Just starting out? Need help? Post your questions and find answers here.
Mr52
User
User
Posts: 12
Joined: Tue Jun 21, 2011 3:59 pm

Byte Array inside Structure Error

Post 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
User avatar
skywalk
Addict
Addict
Posts: 4220
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Byte Array inside Structure Error

Post by skywalk »

Add... Array xi.b(23)
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
STARGÅTE
Addict
Addict
Posts: 2235
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Byte Array inside Structure Error

Post 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
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
Mr52
User
User
Posts: 12
Joined: Tue Jun 21, 2011 3:59 pm

Re: Byte Array inside Structure Error

Post by Mr52 »

wow thank you didnt know PB has Array as keyword :P
User avatar
helpy
Enthusiast
Enthusiast
Posts: 552
Joined: Sat Jun 28, 2003 12:01 am

Re: Byte Array inside Structure Error

Post 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
Windows 10 / Windows 7
PB Last Final / Last Beta Testing
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Byte Array inside Structure Error

Post 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.
BERESHEIT
Post Reply