“在 C99 模式之外使用 ‘for’ 循环初始化声明”错误处理;
示例程序
1: #include <stdio.h>
2:
3: int main()4: {
5: for( int i = 1; i <= 9; i++ )6: {
7: for( int j = 1; j <= i; j++ )8: {
9: printf( "%d x %d = %2d ", i, j, (i*j));10: }
11: printf("\n");12: }
13:
14: return 0;15: }
错误信息:
用gcc 编译出现如下错误:
1: [root@localhost code]# gcc --version
2: gcc (GCC) 4.1.2 20070626 (Red Hat 4.1.2-14)
3: Copyright (C) 2006 Free Software Foundation, Inc.
4: 本程序是自由软件;请参看源代码的版权声明。本软件没有任何担保;
5: 包括没有适销性和某一专用目的下的适用性担保。
6: [root@localhost code]# gcc multiplicationtable.c -o multiplicationtable
7: multiplicationtable.c: 在函数 ‘main’ 中:
8: multiplicationtable.c:5: 错误:在 C99 模式之外使用 ‘for’ 循环初始化声明9: multiplicationtable.c:7: 错误:在 C99 模式之外使用 ‘for’ 循环初始化声明
错误处理:
C99 允许在for语句的 “表达式1 ”中定义并初始变量, gcc4 编译c语言的默认标准是C89, 编译C99程序需加参数 “–-std=c99” 如:
推荐.NET配套的通用数据层ORM框架:CYQ.Data 通用数据层框架