<< Home | About Forth | About TurboForth | Download | Language Reference | Resources | Tutorials | YouTube >>
In String Constant Words in String Library
Declares a string constant. String constants have a fixed size.
50 $CONST WELCOME \ declare a string constant called welcome with maximum size of 50 characters
50 $CONST WELCOME
To initialise the string constant with an actual string, see :=". To get the maximum allowed string length (the length specified when the string constant was created) see MAXLEN$.
:="
MAXLEN$
String constants require a maximum size and a name. Once created, they can hold any string up to, or smaller than the maximum size. Any attempt to load a string constant with a string that exceeds the maximum declared size when the constant was created will cause a run-time error.
When a string constant is referenced in code, it pushes the address of its maximum length field to the stack.