Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NUL char cannot be part of a string? #43

Open
gdelconti opened this issue Nov 4, 2018 · 2 comments
Open

NUL char cannot be part of a string? #43

gdelconti opened this issue Nov 4, 2018 · 2 comments

Comments

@gdelconti
Copy link

gdelconti commented Nov 4, 2018

See example below:

print "ESP Basic 3.0.Alpha 69"

' let define some control character
let NUL = chr(0) 'required
let SOH = chr(1) 'can be any
let STX = chr(2) 'can be any

print "correct with any combitation of control char but the NUL"
let s = SOH & STX
print asc(left(s,1))
print asc(right(s,1))

print "wrong if NUL is part of the string"
let s = NUL & STX
print asc(left(s,1))
print asc(right(s,1))

@oldbodd
Copy link

oldbodd commented Nov 13, 2018

Espbasic is a program written in a programming language created by people who thought it was a good idea to indicate the end of a string with a special character and picked chr(0) for that character. So when you put a chr(0) in a string, the program reads the string till it comes to that Chr(0) and treats it as end of string rather than a character with a value of 0 .. if you see what I mean.... I'm sure this has many advantages but strongly suspect that the phrase buffer overrun is not entirely unrelated to this type of thinking.... Some systems use two bytes to represent one....

@gdelconti
Copy link
Author

I thought this was "C"-related.
BTW, other people from different country in more recent times thought that using NUL char in Relay deactivation command was a good idea too ;-) http://www.smoke.com.au/museum/?p=379

Of course with ESPbasic there is an obvious workaround:

[R1OFF]
' A0 and A1 defined elsewhere
serialprint chr(A0)
serialprint chr(01)
serialprint chr(00)
serialprint chr(A1)
return

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants