Closed reeskm closed 1 year ago
Welcome to the exciting world of Forth. It can be a bit like juggling chain-saws. Things can go wrong.
In Forth, a ? will read an address off the stack and then fetch from the address. But there was no address on the stack. So you fetched from an undefined address. Boom.
A C equivalent might be:
*((char *)lrand48());
As you can see, Forth is more concise.
You might enjoy this Forth tutorial: https://www.softsynth.com/pforth/pf_tut.php
Just curious why this would not be trapped by the interpreter and a general error issued, instead of a segfault? Is this by design or deliberately not implemented?
By design. Forth is often used as an embedded language where you need to be able to access any address when there is no OS. So Forth typically does not validate addresses.
That makes a lot of sense Phil! Thanks for your awesome support.
As a total Forth n00b, I managed to build pforth 2.0.1 release on Solaris 11.3 SPARC. Not knowing what to do at the prompt, I typed '?' for help. I've been able to crash both pforth and pforth_standalone, resulting in a SIGV and core dump. Here's the output of 'dbx':