How to Declare a string as a constant in SPIN?
william chan
Posts: 1,326
Can a string be declared as a constant or it's impossible?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.fd.com.my
www.mercedes.com.my
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.fd.com.my
www.mercedes.com.my
Comments
Cheers
P.S. When is your production going to start?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.fd.com.my
www.mercedes.com.my
We did the OEM design work for that project, the customer will sub the production to production house in Penang.
Cheers
I tried
but both cannot send out the string.
What gives?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.fd.com.my
www.mercedes.com.my
Note the string constant must end with a Zero i.e. BYTE "HelloWorld",0
If you want to add a carriage return to it then
BYTE "HelloWorld",13,0
Cheers
Need something to play with lah.
serial.str(string"Hello World", $0D))
or
serial.str(@StrHelloWorld)
(the @ is required to indicate it is a pointer to the memory)
serial.str(string("Hello World", $0D))
Also (and please correct me if I'm wrong), unless you're using the same string from more than one place in your program, or need to modify the string during execution, there's probably no advantage to using the DAT form.
-Phil
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
'Still some PropSTICK Kit bare PCBs left!
You are absolutely correct. For every STRING() the compiler places an independent copy in the Bytecode.
Using a string in DAT and referencing it multiple times is _far_ more efficient.
Remember kiddies .. strings from STRING() are all null terminated, so make sure to remember the ",0" in the DAT declaration or you might find your strings run on past what you are expecting.*!%@&#*($}}}}}}}}}}}}}}}}^Z^Z^Z^Z^Z^Z
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Pull my finger!
without the $0D at the back (is that a null?) and it still works! without any extra exclamations.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.fd.com.my
www.mercedes.com.my
The null is '0' and is inserted by the compiler when you use STRING(). You only need to add it manually when you
declare a string in the DAT section
DAT
mystring byte "This is my string",0
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Pull my finger!