因为没用过,所以没想过的--goto

今天读了读 Rui Maciel 大神写的 mjson parser,mjson 解析器是一个使用 ISO C 实现的小型 JSON 解析器。嵌入式项目中使用到了该解析器,随即拿出来看看。

看到如下代码:

 enum json_error  json_tree_to_string (json_t * root, char **text)
{
json_t *cursor;
rcstring *output; assert (root != NULL);
assert (text != NULL); cursor = root;
/* set up the output and temporary rwstrings */
output = rcs_create (RSTRING_DEFAULT); /* start the convoluted fun */
state1: /* open value */
{
if ((cursor->previous) && (cursor != root)) /*if cursor is children and not root than it is a followup sibling */
{
/* append comma */
if (rcs_catc (output, ',') != RS_OK)

第14行的标号,有点小疑问,该不该往下执行不太确定,于是只能动手实验:

 /* goto.c */
#include <stdio.h> void print_goto()
{
printf("before goto\n"); label:

printf("after goto\n"); } int main()
{
printf("main\n"); print_goto(); return ;
}
~

执行结果如下:

 wq@ubuntu:~/C_Test$ gcc goto.c -o goto
wq@ubuntu:~/C_Test$ ./goto
main
before goto
after goto
wq@ubuntu:~/C_Test$

说明,标号下面的代码被执行了。

由于从来没有使用过 goto 关键字编程,也就没想过前面没有goto语句时,这里该怎么执行,导致卡在这里;水水的!

继续看代码……

上一篇:笑谈ArcToolbox (4) 非我族类


下一篇:Windows10配置NFS服务端和客户端