Code: Select all
function salut() as string
'' temporary string returned
return "salut"
end function
dim f as function() as any ptr = cast(function() as any ptr, @salut)
dim as STRING ptr tmp = cptr(string ptr, f())
'' passing a temporary string to PRINT will automatically delete it
'' print *tmp '' salut
'' print it as a zstring instead
print *cptr(zstring ptr, cptr(uinteger ptr, tmp)[0]) '' salut
print hex(cptr(uinteger ptr, tmp)[1], sizeof(uinteger) * 2) '' 8000...005
print hex(cptr(uinteger ptr, tmp)[2], sizeof(uinteger) * 2) '' 0000...020
print len(*tmp) '' 5
'' clean-up the temporary (if we didn't already pass it to some other rlib function)
fb_hStrDelTemp( *tmp )
Am I right ?fxm wrote:Finally, I thus found there an explanation on the maximum size of variable strings: 2 ^ (31 or 63) - 1coderJeff wrote:For temporary strings, the most significant bit is set on the 'len' member which is the second member of the string descriptor type.
:-)