On the stack characters take up a cell, like numbers. In memory they have their own size (one 8-bit byte on most systems), and therefore require their own words for memory access:
create v4 104 c, 97 c, 108 c, 108 c, 111 c, v4 4 chars + c@ . v4 5 chars dump
The preferred representation of strings on the stack is
addr is the address of the first character and
u-count is the number of characters in the string.
v4 5 type
You get a string constant with
s" hello, world" .s type
Make sure you have a space between
s" and the string;
is a normal Forth word and must be delimited with white space (try what
happens when you remove the space).
However, this interpretive use of
s" is quite restricted: the
string exists only until the next call of
s" (some Forth systems
keep more than one of these strings, but usually they still have a
s" hello," s" world" .s type type
You can also use
s" in a definition, and the resulting
strings then live forever (well, for as long as the definition):
: foo s" hello," s" world" ; foo .s type type
Emit ( c -- )types
cas character (not a number). Implement
type ( addr u -- ).
Reference: Memory Blocks.