C++中,变量定义可以在函数中的任意位置,比如函数中任意位置出现的For循环中:

for(int i = 0; i< len; i++) {
    /*do something;*/
}

  变量i可以在使用到的地方才给定义;

  然而在C语言中,变量的定义一定要在函数体的开始处;

  否则在使用到变量的地方才定义,编译的时候会报不认识此变量,如下这个屏幕字段入口函数:

Fi_120015_01_CICUSENA()
{
        char acRegFlg[2];

        GetStr("K_C00101",acRegFlg);
        Trim(acRegFlg);
        /*非记名卡跳过 */
        if(acRegFlg[0]=='0')
        {
             return SKIP;
        }

        /*判断输入的姓名是否为拼音*/
        char Name[71];
        int len = 0;
        GetStr("CICUSENA",Name);

        /*取数组长度*/
  /*   len = (sizeof(Name)/sizeof(Name[0])); */
        len = strlen(Name);

        for(int i = 0; i < len; i++)
        {
if(!((Name[i]>'A' && Name[i]<'Z') || (Name[i]>'a' && Name[i]<'z')))
             {
                  v_warning(0,"请输入姓名对应的拼音");
                  return INVALID;
             }
        }
       return 0;
}

  编译,然后出现下面的错误:

[开发]/usr/AAAAA/src/cds/120015>msoe
 ->编译 120015.fe             ...... 120015.c:
"120015.ec", line 248: error: Syntax error before or at: int
"120015.ec", line 250: error: undefined symbol: Name
"120015.ec", line 253: error: undefined symbol: len
"120015.ec", line 253: error: cannot dereference non-pointer type
"120015.ec", line 254: error: Syntax error before or at: int
"120015.ec", line 254: error: undefined symbol: i
"120015.ec", line 254: error: Syntax error before or at: )
"120015.ec", line 260: error: Syntax error before or at: return
"120015.ec", line 260: warning: syntax violation:  empty declaration
120015.c:
"120015.ec", line 248: error: Syntax error before or at: int
"120015.ec", line 250: error: undefined symbol: Name
"120015.ec", line 253: error: undefined symbol: len
"120015.ec", line 253: error: cannot dereference non-pointer type
"120015.ec", line 254: error: Syntax error before or at: int
"120015.ec", line 254: error: undefined symbol: i
"120015.ec", line 254: error: Syntax error before or at: )
"120015.ec", line 260: error: Syntax error before or at: return
"120015.ec", line 260: warning: syntax violation:  empty declaration
*** Error code 2 (bu21)
mv: cannot access 120015.so: No such file or directory (error 2)