Page 1 of 1
Posted: Tue Nov 26, 2002 10:01 am
by BackupUser
Restored from previous forum. Originally posted by talun.
Dear all,
I was not able to found in this Forum and in the PureBasic help, informations related to the use of square brackets in PureBasic programs.
Can anyone help me?
Thanks a lot
Sergio
Posted: Tue Nov 26, 2002 10:29 am
by BackupUser
Restored from previous forum. Originally posted by Danilo.
Code: Select all
Structure mytest
byte.b[5]
EndStructure
x.mytest
x\byte[0] = 'H'
x\byte[1] = 'E'
x\byte[2] = 'L'
x\byte[3] = 'L'
x\byte[4] = 'O'
x\byte[5] = 0
MessageRequester("",PeekS(x),0)
cya,
...Danilo
(registered PureBasic user)
Posted: Tue Nov 26, 2002 11:53 am
by BackupUser
Restored from previous forum. Originally posted by fred.
In fact, there is a subtility. in structure, byte.b[5] actually allocate 5 elements from 0 to 4. It's not like nomal arrays, which allocate from 0 to 5. You may ask 'Why ?'.. It's because C langage use this def, and as PB support all the API, it had to conform to C to convert all the headers, which make huge use of such arrays.
Fred - AlphaSND
Posted: Tue Nov 26, 2002 12:16 pm
by BackupUser
Restored from previous forum. Originally posted by talun.
Hi Danilo and Fred,
many thanks for your help.
Therefore if I don't have misunderstood, the square brackets notation allows to access data elements located at specific address in memory by using a kind of indexed pointers. It's wrong?
bye
Sergio
Posted: Tue Nov 26, 2002 2:36 pm
by BackupUser
Restored from previous forum. Originally posted by fred.
No, that's exactly its purpose. When associate a structure to a pointer you can access a memory zone very easely.
Fred - AlphaSND