BYREF parameters or typedefs can be used to create pointers to fixed-length strings:
sub f1( byref x as zstring * 1 )
print x
end sub
f1( "abc" )
type S as zstring * 1
dim p as S ptr
Also, BYREF function results are/will be affected:
function f2( ) byref as zstring * 1
function = "abc"
end function
print f2( )
However the compiler does not allow direct declarations such as:
dim p as zstring * 123 ptr
The compiler should be more consistent, allowing it either always or never. Since currently the compiler is internally not able to represent a pointer to a fixed-length string (the length is not preserved on the expression type when taking the address of a variable like that), it's probably best to disallow it all-together.
As for typedefs, this raises another question. What should the following do?
Currently the
*3just overrides the*2, this is inconsistent with how typedefs sum up PTRs at least. Should zstring * 2 * 3 be multiplied together to give a zstring * 6?Also, should a
byref s as zstring * 1be different from abyref s as zstring? (that's currently hard to distinguish in cSymbolType() because their type length is the same)Last edit: dkl 2013-02-18
Possibly related:
Consequently, the address of each array element (except the first) is badly computed in the procedure body:
Last edit: fxm (freebasic.net) 2013-06-02
For the problem of passing a zstring array to a procedure, a fix could be to use the 'element_len' field in the descriptor and not the size of the declared parameter type.
This could be even applied systematically to all arrays passed as parameters to procedures.
See the other bug reports BUG #867 and BUG #911.
Example:
(For fbc rev 1.07, use 'fb_ArrayGetDesc()' instead of 'FBC.ArrayDescriptorPtr()' for fbc rev 1.08 as here)
Last edit: fxm (freebasic.net) 2019-09-24