What is the lifespan of S "..." at Fort?

I am trying to read about it, but I cannot find mention of it.

According to the standard, a string created with S" cannot be changed, and from a simple experiment in Gforth this obviously is this space for the string does not come from a dictionary or spacing areas:

 hex here . 7F48AB3B8758 ok pad . 7F48AB3B8808 ok s" test" .s <2> 77FDD0 4 ok 

How long can I expect the address to be valid?

In other words, if I save this address (and account) in a variable, can I return to it later in the program, or do I need to move it to a separate place in the dictionary or to a bunch? And if I don’t save the address, will I be a memory leak?

+6
source share
1 answer

When compiled into a definition, the lifetime of the string matches the definition. s" usually used only at compile time.

Not all Forths even allow you to use the interpretation of time s" and ANS says," The interpretation semantics for this word are undefined. "The behavior will be at least specific to your particular Forth.

You seem to be using Gforth, which has a reserved space for at least one line of interpretation time. The Gforth manual says: β€œ... a line exists only until the next call to s" . ”It goes on to say:β€œ Some Forth systems contain more than one of these lines, but usually they still have a limited lifespan. ”( Section 3.24 Characters and Strings )

I hope this helps!

+7
source

Source: https://habr.com/ru/post/926605/


All Articles