There is really, really a wealth of information in certain threads. Plenty to learn from, but unfortunately seldom commented (the actual code samples/snippets).
This would IMHO dramatically lower the 'entry barrier' faced by beginner/intermediate programmers. I'm going to add some code from a recent thread as a sample:
Code: Select all
' ===== forum "Byte->string" / Q:VANYA A:fxm =====
' http://www.freebasic.net/forum/viewtopic.php?f=2&t=21326 '
Function i() As String ' func. i is to return a string
' () = NO parameters 'to' the func.
Dim As Byte Ptr p = Allocate(10) ' p = 0 to 9 (BASE = 0), allocates the
' memory used (10 bytes)
For j As Integer = 0 To 9 ' j = index of p[] in for/next loop
p[j] = j+83 ' 83 = offset of "S" in ASCII-table
Next ' above -> Headache (figuring it out)
Dim As String Ptr s = Allocate(Sizeof(String)) ' see p above
Cast(Any Ptr Ptr, s)[0] = p ' define lbound p
Cast(Integer Ptr, s)[1] = 10 ' define usefull string lenght (nr. of
' char)
Cast(Integer Ptr, s)[2] = 10+1 ' define ubound p (terminator = chr(0))
Function = *s ' dereferenced string ptr = string
' Functions 'return'
DeAllocate s ' last Allocate -> DeAllocate first
DeAllocate p ' first Allocate -> DeAllocate last
End Function ' necessary to prevent memory-leakage
? i ' ? = print, in this context ?!?
' still has me guessing ...
sleep ' wait for user action (keypess)
' to prevent immediate close of
' console 'output' ...
I'm not even certain if I got it correct in all instances (in my comments), so please correct me in case of error. I'm aware of the fact that many programmers dislike doing that but it would help a lot to understand the solution approach. At least when a specific problem has been solved. Comments wellcome ...