Its all messed up and totally inconsistent and inconsequent.
This has absolutely nothing to do with good and clean
programming language design. Its an illogical mix-up on every
corner and its all confusing.
See this:
Code: Select all
Structure xyz
*p.POINT
EndStructure
a.xyz
a\*p = AllocateMemory(1,SizeOf(POINT)) ; SYNTAX ERROR
Syntax Error, fine.
Now i´ve seen people using it without the '*':
Code: Select all
Structure xyz
*p.POINT
EndStructure
a.xyz
a\p = AllocateMemory(1,SizeOf(POINT)) ; OK, Works
Thats not logical, because PB doesnt use pointers like C where
you specify '*' sometimes and sometimes not.
OK, let us continue:
Code: Select all
Structure xyz
*p.POINT
EndStructure
a.xyz
a\p = AllocateMemory(1,SizeOf(POINT)) ; OK, Works
a\p\x = 12
Writing seems to work... doesnt crash here.
Let us test reading:
Code: Select all
Structure xyz
*p.POINT
EndStructure
a.xyz
a\p = AllocateMemory(1,SizeOf(POINT)) ; OK, Works
Debug a\p\x ; reading works
Test successful, works.
Now lets test both together, reading and writing:
Code: Select all
Structure xyz
*p.POINT
EndStructure
a.xyz
a\p = AllocateMemory(1,SizeOf(POINT)) ; OK, Works
a\p\x = 12 ; ??
Debug a\p\x ; ??
Ooohhh.. it crashes with debugger enabled. With disabled
debugger it doesnt crash. Hmm, OK.
If i make the last line (Debug..) a comment, it doesnt crash
anymore.
Lets try to exchange the last 2 lines, maybe it works...
Code: Select all
Structure xyz
*p.POINT
EndStructure
a.xyz
a\p = AllocateMemory(1,SizeOf(POINT)) ; OK, Works
Debug a\p\x ; ??
a\p\x = 12 ; ??
Oi! Now the debug line doesnt crash, but the debugger says
"pointer is 0" on the last line.
I´m confused, nothing works. And now the 0-Array length ??
Whats that ?? A word-array with length 0 is nothing, but
debugger says its 2 bytes long.
Code: Select all
Structure WORDArray
w.w[10]
EndStructure
p.WORDArray
p\w[0] = 12
p\w[100000] = 8000 ; debugger gives error,
; array index out of bounds.
Thats the correct way, works.
Now the wrong way:
Code: Select all
Structure WORDArray
w.w[0]
EndStructure
p.WORDArray
p\w[0] = 12
p\w[100000] = 8000
...just crashes.
There is absolutely no logic and consistency in this stuff, sorry.
An array with size 0 is NOTHING. 0 = NULL = NOTHING.
Its magic... in PB 'nothing' is 2 bytes long if 'nothing' is a word.
There is another thread in the forum that shows that pointers
dont work correctly because all is messed up, especially with
pointers in structures.
A simple '*p.LONG = malloc(1000)' and '*p + 4' works fine, but
thats all...
And now a little brain-teaser for the smart guys:
Code: Select all
Structure xyz
*p.POINT
p.SIZE
EndStructure
a.xyz
a\p = AllocateMemory(1,SizeOf(POINT))
The question is, which 'p' is accessed in the last line, the
pointer '*p' or 'p' ??
All this isnt in the manual because its all messed up, thats it.
