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


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

    看到如下代码:

     1 enum json_error  json_tree_to_string (json_t * root, char **text)
     2 {
     3     json_t *cursor;
     4     rcstring *output;
     5 
     6     assert (root != NULL);
     7     assert (text != NULL);
     8 
     9     cursor = root;
    10     /* set up the output and temporary rwstrings */
    11     output = rcs_create (RSTRING_DEFAULT);
    12 
    13     /* start the convoluted fun */
    14     state1:            /* open value */
    15     {
    16         if ((cursor->previous) && (cursor != root))    /*if cursor is children and not root than it is a followup sibling */
    17         {
    18             /* append comma */
    19             if (rcs_catc (output, ',') != RS_OK)

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

     1 /* goto.c */
     2 #include <stdio.h>
     3 
     4 void print_goto()
     5 {
     6         printf("before goto
    ");
     7 
     8 label:
     9 
    10         printf("after goto
    ");
    11 
    12 }
    13 
    14 int main()
    15 {
    16         printf("main
    ");
    17         
    18         print_goto();
    19         
    20         return 0;
    21 }
    22 ~       

    执行结果如下:

    1 wq@ubuntu:~/C_Test$ gcc goto.c -o goto
    2 wq@ubuntu:~/C_Test$ ./goto
    3 main
    4 before goto
    5 after goto
    6 wq@ubuntu:~/C_Test$ 

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

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

    继续看代码……

  • 相关阅读:
    Debug和Release区别
    C语言程序_管理系统
    读书的学问
    御姐的含义
    进制的英文书写
    CHM文件无法打开的解决方法
    819代码
    点击链接不跳转或刷新
    MS SqlServer 随机查询并随机排序
    Html背景图
  • 原文地址:https://www.cnblogs.com/gongxing/p/5896907.html
Copyright © 2020-2023  润新知