一、
Eclipse CDT 解决 "for loop initial declaration used outside C99 mode" 错误
在用 Eclipse CDT 编写c程序时出现 `for' loop initial declaration used outside C99 mode 错误是因为加 -std=c99 选项
C99标准支持下面这种for 循环的变量i的定义及初始化方式:
for (int var = 0; var < 10; ++var) {
}
C99标准之外的C标准支持下面这种for 循环的变量i的定义及初始化方式:
int var;
for (var = 0; var < 10; ++var) {
}
解决办法:
右键点击项目->Properties->C/C++ Build -> Settings -> Tool Settings -> GCC C Complier -> Miscellaneous
在 "Other flags" 中追加 -std=c99
二、
/usr/include/pcap/bpf.h:88:1: error: unknown type name ‘u_int’
/usr/include/pcap/bpf.h:108:2: error: unknown type name ‘u_int’
/usr/include/pcap/bpf.h:1260:2: error: unknown type name ‘u_short’
/usr/include/pcap/bpf.h:1261:2: error: unknown type name ‘u_char’
/usr/include/pcap/bpf.h:1262:2: error: unknown type name ‘u_char’
In file included from ../src/test.c:1:0:
/usr/include/pcap/pcap.h:125:2: error: unknown type name ‘u_short’
/usr/include/pcap/pcap.h:126:2: error: unknown type name ‘u_short’
/usr/include/pcap/pcap.h:171:2: error: unknown type name ‘u_int’
http://stackoverflow.com/questions/15393905/c-pcap-library-unknown-types-error
解决方法:
Actually, yes, you did define at least one of them, by specifying -std=c99. The GCC man page says -std= has the same effect as -ansi, and -ansi defines __STRICT_ANSI__. -std=c99 may define _ISOC99_SOURCE as well as, or instead of, __STRICT_ANSI__. -std=c99 means you want your code to be compiled as strict ISO C99, meaning it can't use any features not in ISO C99 - and libpcap isn't in ISO C99, so.... If you're trying to use C99 features and they're not supported by default, try -std=gnu99.
其实就是 类似于二中的解决方案 添加-std=gnu99
三、
unknown type name 'socklen_t'
解决方法: 加上 #include "WS2tcpip.h"
四、
如果 while(true)报错
改成while (1) 就可以了