whartung wrote:
Specifically to the issue with ALLOT, the C Standard cleverly avoids the problem entirely by specifying the size parameter to be of type size_t, which is unsigned.
Any of the Forth standards could have specified that an error condition exists ( with the possibility of
ALLOT aborting or, in the new standard, throwing an exception) if the parameter for
ALLOT is negative. I don't think any of them did and I'm glad. I have on occasion used a negative value with
ALLOT , but then Fleet Forth is a Forth-83 standard Forth.
Quote:
The specification seems pretty clear:
Quote:
If n is greater than zero, reserve n address units of data space. If n is less than zero, release | n | address units of data space. If n is zero, leave the data-space pointer unchanged.
They also have this caveat (not mentioned in ALLOT):
Quote:
An ambiguous condition exists if deallocated memory contains definitions.
They go into reasonable detail about the behavior of ALLOT and what Contiguous Data Regions are, and their limitations. The "ambiguous condition" mentioned seems to cover a lot of ground as to what happens with over zealous use of negative ALLOT.
Like all of the memory manipulation words in Forth (
! C! CMOVE CMOVE> MOVE for example ) , it is the programmer's responsibility to use
ALLOT carefully.