What is the difference between the two words CREATE and VARIABLE?
For example, in this code:
VARIABLE MYARRAY 2 CELLS ALLOT
170 340 220 MYARRAY ! MYARRAY 1 CELLS + ! MYARRAY 2 CELLS + !
CREATE MYARRAY 220 , 340 , 170 ,
In both cases the result is the same in memory. Is it right? When should I use one in place of the other? And why?
Right, VARIABLE
allocates one cell of memory. Also, a standard program may not assume that it can
add data after the variable, see Contiguous regions.
CREATE
does not by itself allocate any memory, but starts a contiguous region which can be extended. And, it's the only word which a standard program may use in combination with DOES>
.
The difference may be mostly stylistic (unless you use DOES>
or care deeply about the standard). It's more clear to a reader that VARIABLE
is a plain variable. CREATE
can be any type of data structure.
If you want an initialised variable, you can use either VARIABLE FOO BAR FOO !
or CREATE FOO BAR ,
. I don't see that either alternative is preferred over the other to a significant degree.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With