Code: Select all
Define mystring.s
Debug @""
Debug @mystring
Debug mystring ; <<<<<<<< An error message about a null pointer variable is expected but this is handles as an empty string variable ("")
Code: Select all
Define mystring.s
Debug @""
Debug @mystring
Debug mystring ; <<<<<<<< An error message about a null pointer variable is expected but this is handles as an empty string variable ("")
correct.Trond wrote:Huh? Null pointer strings are valid strings in PureBasic. There is not supposed to be an error message.
I noticed this behavior when I try to fill an uninitialized string variable passed to a procedure ByRef.freak wrote:This is the intended behavior. Strings are only initialized when something is assigned to them. A nullpointer is always interpreted as the empty string internally. This is how it was designed from the start.
Code: Select all
Procedure EditStr(*p)
PokeS(*p,"Hello")
ProcedureReturn Len(PeekS(*p))
EndProcedure
Define.s r2;="" ;<--- remove comment and it works
Debug EditStr(@r2)
It works sometimes with removed comment but it is not correct. You poke in a not reserved memory. Enable purifierskywalk wrote:Is this correct?
Code: Select all
Procedure EditStr(*p) PokeS(*p,"Hello") ProcedureReturn Len(PeekS(*p)) EndProcedure Define.s r2;="" ;<--- remove comment and it works Debug EditStr(@r2)
True, I left out the other stuff in the procedure for simplicity.ts-soft wrote:It works sometimes with removed comment but it is not correct. You poke in a not reserved memory. Enable purifier to see that it not works!
Code: Select all
Procedure EditStr(*p)
*p = AllocateMemory(RLen)
; do stuff...
PokeS(*p,"Hello")
FreeMemory(*p)
EndProcedure
Define.s r2;="" ;<--- remove comment and it works
Debug EditStr(@r2)
There is only place for the nullbyte, so you can only poke a empty stringskywalk wrote:What amount of memory is reserved when r2 = ""?
Code: Select all
Procedure EditStr(*p)
Protected *s.STRING = AllocateMemory(SizeOf(STRING))
PokeI(*s, *p)
*s\s = "Hello"
FreeMemory(*s)
ProcedureReturn Len(PeekS(*p))
EndProcedure
Define.s r2=""
Debug EditStr(@r2)
Debug r2
Code: Select all
Procedure AppendString( *First.String, *Second.String )
*First\s + *Second\s
EndProcedure
Procedure EmptyString( *aString.String )
*aString\s = ""
EndProcedure
First.String
Second.String
First\s = "Hello"
Debug First\s
Second\s = ", this was appended to the orignial string without any problems :-)"
AppendString( First, Second )
Debug First\s
Second\s = #CRLF$ + #CRLF$ + "Und noch mehr" + RSet("",1024,"-")
AppendString( First, Second )
Debug First\s
EmptyString( First )
Debug #DQUOTE$ + First\s +#DQUOTE$