所以我有以下C代码:
for (int i = 0; i < nWallSegments; i+=4) { fscanf(fin, "%le %le %le %le", &wallSegments[i+0], &wallSegments[i+1], &wallSegments[i+2], &wallSegments[i+3]); } for (int i = 0; i < nWallSegments; i+=4) { nWallPoints += ceil(dist(wallSegments[i+0], wallSegments[i+1], wallSegments[i+2], wallSegments[i+3]) / dWallPoints) - 2; // other stuff here }
当我尝试编译时,我收到以下错误.来自Python背景,我不知道发生了什么.我在网上搜索了答案,但没有运气.
Prog.c:44:12: error: redefinition of 'i' for (int i = 0; i < nWallSegments; i+=4) { ^ Prog.c:40:12: note: previous definition is here for (int i = 0; i < nWallSegments; i+=4) {c
pablo1977.. 6
它取决于编译器和/或标准C的版本.
在标准C 1999及更高版本(C99和C11)中,允许在循环中声明一个变量,而且,范围只是循环,就像在C++中一样.
通过使用一些现代C语言进行编译,您的代码必须正常运行.
我使用GCC选项-std = c99(或c11).
在这种情况下,您的代码适合我.
它取决于编译器和/或标准C的版本.
在标准C 1999及更高版本(C99和C11)中,允许在循环中声明一个变量,而且,范围只是循环,就像在C++中一样.
通过使用一些现代C语言进行编译,您的代码必须正常运行.
我使用GCC选项-std = c99(或c11).
在这种情况下,您的代码适合我.