There were a couple of minor problems in the proposed subroutine which I've fixed in the rendition below. The first is that the array
d() is 1-based in ZBasic so the variable
i must be initialized to 1. The second problem is that you must use the
Chr() function when you append the characters to the string.
Code: Select all
Public Sub DisplayStr_C(ByVal strAddr as UnsignedInteger)
Dim d() as Byte Based strAddr
Dim str as String = ""
Dim i as byte = 1
Do
If (d(i) = 0) Then
Exit Do
End If
str = str & Chr(d(i))
i = i + 1
Loop
Call DisplayStr(str)
End Sub
As for the
const char * formal parameter needed by your C calling routine, it wouldn't make sense for ZBasic to generate code with a
const char * parameter corresponding to a ZBasic integral value. If we did, then code that needed to modify the memory at that address wouldn't work.
The solution is to introduce an intermediary function in your C code that takes a
const char * parameter and casts it to an integral value to match the ZBasic subroutine parameter. The example code below may work for that purpose. Depending on how it is used in the C code you may be able to replace it with a #define.
Code: Select all
void
intermediary(const char *str)
{
zf_DisplayStr_C((uint16_t)(void *)str);
}