Page 1 of 1

Shouldn't this return an empty string?

Posted: Wed Oct 27, 2010 11:54 pm
by Mistrel
I'm writing a preceding null in front of the string I'm poking. Shouldn't I get a blank string? The character doesn't seem to be written at all.

Code: Select all

*Mem=AllocateMemory(500)

String.s=""
For i=1 To 6
  String.s+"7"
Next i

;/ No preceding null is written
PokeS(*Mem+16,Chr(0)+String.s,Len(String.s)+1)

;/ Chr(6) is correctly written
;PokeS(*Mem+16,Chr(6)+String.s,Len(String.s)+1)

Debug PeekS(*Mem+16)

Debug PeekC(*Mem+16)

Re: Shouldn't this return an empty string?

Posted: Thu Oct 28, 2010 1:05 am
by IdeasVacuum
Try this:

Code: Select all

PokeS(*Mem, Chr(Null) + sString, (Len(sString) + 2) )

Re: Shouldn't this return an empty string?

Posted: Thu Oct 28, 2010 1:09 am
by Demivec
Mistrel wrote:I'm writing a preceding null in front of the string I'm poking. Shouldn't I get a blank string? The character doesn't seem to be written at all.
A null, or Chr(0), isn't a string it's a terminator. It shows the end of a string. That being said, I agree that it should function as you expected.

Compare these two:

Code: Select all

string.s = "777777"
;/ No preceding null is written
PokeS(*Mem+16,Chr(0)+string.s,Len(string.s)+1)
Debug PeekS(*Mem+16)
Debug PeekC(*Mem+16)

;/It works as you would expect with a string constant
PokeS(*Mem+16,Chr(0)+"333",Len("333")+1)
Debug PeekS(*Mem+16)
Debug PeekC(*Mem+16)
It looks like it may be a bug.

Re: Shouldn't this return an empty string?

Posted: Thu Oct 28, 2010 2:23 am
by IdeasVacuum
A zero could be a bona fide member of a string? I don't know, but Null = Null and should always work.

Re: Shouldn't this return an empty string?

Posted: Thu Oct 28, 2010 2:31 am
by Vitor_BossĀ®
Demivec wrote:
Mistrel wrote:I'm writing a preceding null in front of the string I'm poking. Shouldn't I get a blank string? The character doesn't seem to be written at all.
A null, or Chr(0), isn't a string it's a terminator. It shows the end of a string. That being said, I agree that it should function as you expected.

Compare these two:

Code: Select all

string.s = "777777"
;/ No preceding null is written
PokeS(*Mem+16,Chr(0)+string.s,Len(string.s)+1)
Debug PeekS(*Mem+16)
Debug PeekC(*Mem+16)

;/It works as you would expect with a string constant
PokeS(*Mem+16,Chr(0)+"333",Len("333")+1)
Debug PeekS(*Mem+16)
Debug PeekC(*Mem+16)
It looks like it may be a bug.
If first code are compiled in ASCII the NULL char isn't write? On Unicode mode all char less than 255 use a Char(0) before the number, like 00FF for Chr(255), you tried use double null chars in unicode programs?

Re: Shouldn't this return an empty string?

Posted: Thu Oct 28, 2010 2:37 am
by freak
Chr(0) is cannot be part of a string. It marks the end of a string. So all you get is an empty string.

> Chr(0)+string.s

You add nothing to the beginning string.s. So you end up with the original string.

> Chr(0)+"333"

The reason this seems to work is because it is resolved at compile-time. Its a side-effect of the optimization for literal Chr() calls.

Re: Shouldn't this return an empty string?

Posted: Thu Oct 28, 2010 11:40 am
by Mistrel
freak wrote:You add nothing to the beginning string.s. So you end up with the original string.
I guess it makes sense. Chr(0) resolves to an empty string.

That's not exactly what I was expecting but it is the logical result. I've adjusted my code to PokeC the null and then PokeS the string.
freak wrote:The reason this seems to work is because it is resolved at compile-time. Its a side-effect of the optimization for literal Chr() calls.
Would you classify this as an actual bug or an acceptable one?

Re: Shouldn't this return an empty string?

Posted: Thu Oct 28, 2010 1:16 pm
by IdeasVacuum
...I think we have all missed the obvious question then - why are you trying to prefix a null?