Jeff,
Back to : Pass Byref to a function, Return Byref from a function
Assignment of the 3 types of string (
'String',
'String * N',
'Zstring * N+1') by calling 2 types of function (
'Byref As String',
'Byref As Zstring'):
- either passing by reference to the function,
- or returning by reference from the function.
Example :
Code: Select all
#macro printStringUbytes(s)
Print "[" & s & "](";
For I As Integer = 0 To Len(s) - 1
Print (s)[I];
If I < Len(s) - 1 Then
Print " ";
End If
Next I
Print ")";
#endmacro
#macro printTestResult(s, s0)
Print " ";
If s = s0 Then
Print "OK"
Else
Print "NON OK,"
Print " could have been : ";
printStringUbytes(s0)
Print
End If
#endmacro
Print "1. Pass/Return to/from a 'Byref As String' function :"
Function testByrefString(Byref s As String) Byref As String
Print " => ";
s = "12 "
Return s
End Function
Scope
Dim As String s = "1 "
Print " 1.1 String :"
Print " pass : ";
printStringUbytes(s)
testByrefString(s)
printStringUbytes(s)
printTestResult(s, "12 ")
s = "1 "
Print " return : ";
printStringUbytes(s)
(testByrefString(s)) = "123 "
printStringUbytes(s)
printTestResult(s, "123 ")
End Scope
Scope
Dim As String * 5 s = "1 "
Print " 1.2 String * 5 :"
Print " pass : ";
printStringUbytes(s)
testByrefString(s)
printStringUbytes(s)
#if __FB_VERSION__ >= "1.20.0"
printTestResult(s, "12 ")
#else
printTestResult(s, "12 ")
#endif
s = "1 "
Print " return : ";
printStringUbytes(s)
(testByrefString(s)) = "123 "
printStringUbytes(s)
#if __FB_VERSION__ >= "1.20.0"
printTestResult(s, "123 ")
#else
printTestResult(s, "123 ")
#endif
End Scope
Scope
Dim As Zstring * 5+1 s = "1 "
Print " 1.3 Zstring * 5+1 :"
Print " pass : ";
printStringUbytes(s)
testByrefString(s)
printStringUbytes(s)
printTestResult(s, "12 ")
s = "1 "
Print " return : ";
printStringUbytes(s)
(testByrefString(s)) = "123 "
printStringUbytes(s)
printTestResult(s, "123 ")
End Scope
Print
Print "2. Pass/Return to/from a 'Byref As Zstring' function :"
Function testByrefZstring(Byref s As Zstring) Byref As Zstring
Print " => ";
s = "12 "
Return s
End Function
Scope
Dim As String s = "1 "
Print " 2.1 String :"
Print " pass : ";
printStringUbytes(s)
testByrefZstring(s)
printStringUbytes(s)
printTestResult(s, "12 ")
s = "1 "
Print " return : ";
printStringUbytes(s)
(testByrefZstring(s)) = "123 "
printStringUbytes(s)
printTestResult(s, "123 ")
End Scope
Scope
Dim As String * 5 s = "1 "
Print " 2.2 String * 5 :"
Print " pass : ";
printStringUbytes(s)
testByrefZstring(s)
printStringUbytes(s)
#if __FB_VERSION__ >= "1.20.0"
printTestResult(s, "12 ")
#else
printTestResult(s, "12 ")
#endif
s = "1 "
Print " return : ";
printStringUbytes(s)
(testByrefZstring(s)) = "123 "
printStringUbytes(s)
#if __FB_VERSION__ >= "1.20.0"
printTestResult(s, "123 ")
#else
printTestResult(s, "123 ")
#endif
End Scope
Scope
Dim As Zstring * 5+1 s = "1 "
Print " 2.3 Zstring * 5+1 :"
Print " pass : ";
printStringUbytes(s)
testByrefZstring(s)
printStringUbytes(s)
printTestResult(s, "12 ")
s = "1 "
Print " return : ";
printStringUbytes(s)
(testByrefZstring(s)) = "123 "
printStringUbytes(s)
printTestResult(s, "123 ")
End Scope
Sleep
- - With fbc version 1.10.0:
Code: Select all
1. Pass/Return to/from a 'Byref As String' function :
1.1 String :
pass : [1 ](49 32 32 32 32) => [12 ](49 50 32) OK
return : [1 ](49 32 32 32 32) => [123 ](49 50 51 32) OK
1.2 String * 5 :
pass : [1 ](49 32 32 32 32) => [12 ](49 50 32) OK
return : [1 ](49 32 32 32 32) => [12 ](49 50 32) NON OK,
could have been : [123 ](49 50 51 32)
1.3 Zstring * 5+1 :
pass : [1 ](49 32 32 32 32) => [1 ](49 32 32 32 32) NON OK,
could have been : [12 ](49 50 32)
return : [1 ](49 32 32 32 32) => [1 ](49 32 32 32 32) NON OK,
could have been : [123 ](49 50 51 32)
2. Pass/Return to/from a 'Byref As Zstring' function :
2.1 String :
pass : [1 ](49 32 32 32 32) => [12 ](49 50 32 0 32) NON OK,
could have been : [12 ](49 50 32)
return : [1 ](49 32 32 32 32) => [123 ](49 50 51 32 0) NON OK,
could have been : [123 ](49 50 51 32)
2.2 String * 5 :
pass : [1 ](49 32 32 32 32) => [12 ](49 50 32) OK
return : [1 ](49 32 32 32 32) => [123 ](49 50 51 32) OK
2.3 Zstring * 5+1 :
pass : [1 ](49 32 32 32 32) => [12 ](49 50 32) OK
return : [1 ](49 32 32 32 32) => [123 ](49 50 51 32) OK
- With fbc version 1.20.0:
Code: Select all
1. Pass/Return to/from a 'Byref As String' function :
1.1 String :
pass : [1 ](49 32 32 32 32) => [12 ](49 50 32) OK
return : [1 ](49 32 32 32 32) => [123 ](49 50 51 32) OK
1.2 String * 5 :
pass : [1 ](49 32 32 32 32) => [12 ](49 50 32 32 32) OK
return : [1 ](49 32 32 32 32) => [12 ](49 50 32 32 32) NON OK,
could have been : [123 ](49 50 51 32 32)
1.3 Zstring * 5+1 :
pass : [1 ](49 32 32 32 32) => [12 ](49 50 32) OK
return : [1 ](49 32 32 32 32) => [12 ](49 50 32) NON OK,
could have been : [123 ](49 50 51 32)
2. Pass/Return to/from a 'Byref As Zstring' function :
2.1 String :
pass : [1 ](49 32 32 32 32) => [12 ](49 50 32 0 32) NON OK,
could have been : [12 ](49 50 32)
return : [1 ](49 32 32 32 32) => [123 ](49 50 51 32 0) NON OK,
could have been : [123 ](49 50 51 32)
2.2 String * 5 :
pass : [1 ](49 32 32 32 32) => [12 ](49 50 32 0 32) NON OK,
could have been : [12 ](49 50 32 32 32)
return : [1 ](49 32 32 32 32) => [12 ](49 50 32 0 32) NON OK,
could have been : [123 ](49 50 51 32 32)
2.3 Zstring * 5+1 :
pass : [1 ](49 32 32 32 32) => [12 ](49 50 32) OK
return : [1 ](49 32 32 32 32) => [123 ](49 50 51 32) OK
For fbc version 1.20.0 only:
- Can you correct the cases '2.1 pass' and '2.2 pass' at least ?
(the '0' of the terminal character of zstring does not play its role of end)
- Could you correct other 'NON OK' cases ('return' cases) ?
- Note: Only the cases '1.1' and '1.2' are compatible with the use of Chr(0) by user, and the results are similar (only the case '1.2 return' fails).