事实证明
S"
不创建以null结尾的字符串,也不会将地址独占地推送到堆栈上。
S“
创建一个临时位置(至少在下次调用
S“
)并将长度和地址推送到堆栈中。
之后
S“
称为长度在栈顶,这个顺序很重要。
下面是一个交互式会话的示例
gforth
和一个提示(
>
)为了清晰起见插入。
$ gforth
> S" a" ( define a new string, push length and addr )
> .s ( display size of stack and contents of stack )
<2> 22565888 1
> . ( print and drop top item of stack )
1
> .s ( display size and contents of stack again )
<1> 22565888
bye
世界
s\"
就像
,只不过它支持C风格的字符串转义。它劫持“读者”的方式与
S“
是的,但执行一些翻译。
记住所有这些,下面是一个脚本的实现,它调用
printf-
正确地。
#! /usr/bin/env gforth
\c #include <stdio.h>
c-function printf- printf a -- n
( synonym for drop for documentation purposes.
remove the initial length of a length, bytes pair created by
S" or s\" )
: drop-cstr-length drop ;
s\" hello world\n\0" drop-cstr-length
printf-
bye
哪个指纹
hello world
然后正常退出。