Munair wrote:It may not be every days programming practice, but it wouldn't hurt to cover some of it in the manual.
I would like to hear from
other users before adding this kind of detail note in the documentation:
This note could be added at the description paragraph end of the
ZSTRING page:
.....
Note : When any operand of the '=' operator (assignment or equal) consists in dereferencing a 'Zstring Ptr' pointer ('pz'), this can give a 'Zstring' string or a 'Ubyte' character, depending on the other operand. If the other operand is numeric, so the dereferenced 'Zstring Ptr' pointer ('*pz') will be treated as a 'Ubyte' reference to the one character pointed. If a 'Zstring' pointer indexing '[]' operator is used as dereferencing syntax ('pz[n]'), it is basically a short-cut version of the 'String' indexing '[]' operator ('(*pz)[n]).
Example:
Code: Select all
Dim As Zstring * 10 z = "freebasic"
Dim As Zstring Ptr pz = @z
Dim As Ubyte b
Print *pz
*pz = 70 '' 70=Asc("F") is numeric, *pz is treated as ubyte
pz[4] = 66 '' 66=Asc("B") is numeric, pz[4] is treated as ubyte (short-cut version of (*pz)[4])
Print *pz '' *pz is treated as zstring
If pz[4] = 66 Then Print "OK" '' 66=Asc("B") is numeric, pz[4] is treated as ubyte (short-cut version of (*pz)[4]
b = *pz '' b is ubyte, *pz is treated as ubyte
Print b
b = pz[4] '' b is ubyte, pz[4] is treated as ubyte (short-cut version of (*pz)[4])
Print b
If b = pz[4] Then Print "OK" '' b is ubyte, pz[4] is treated as ubyte (short-cut version of (*pz)[4])
Sleep
[edit]
- Replace 'traited' with 'treated'.