I'm trying to store a string value into a variable. To define the variable, I use:
: define CREATE 0 , ;
define x
I can easily store an integer/float value to x
using
10 x !
or
10.0e x f!
And to access it I use either @
or f@
. Now I'm trying to store a string value:
s" hello world" x !
The problem with this is that it pushes two values to the stack (since it's a counted string) but x !
will only store the item on top, which is the length of the string. This is dangerous since the stack content might have been modified by the time x
is referenced such that the address is not directly below the length (bad!), so type
would fail. So my question is, is there a way to store both values (address and length) to x
? Or is there a different data type/operand that would let me achieve this?
Any help is appreciated.