我正在尝试在Windows 7上使用GCC / MinGW编译某些example C code。示例代码包括一些本地头文件,这些文件最终包括stdio.h,在尝试编译时出现此错误:
c:\mingw\include\stdio.h:345:12: error: expected '=', ',', ';', 'asm' or '__attribute__' before '__mingw__snprintf'
extern int __mingw_stdio_redirect__(snprintf)(char*, size_t, const char*, ...);
这对我来说很奇怪。 stdio.h中怎么可能有错误?
最佳答案
关于:
if (i == 0)
{
printf("\nNo interfaces found! Make sure WinPcap is installed.\n");
return 0;
}
pcap_freealldevs(alldevs);
由于变量
i
初始化为0并且从不修改,因此该if()
语句将始终为true
。结果之一是调用:pcap_freealldev()
将永远不会被调用。变量的
scope
应该尽可能地受到限制。代码绝不应该依赖操作系统来自行清理。建议
#include <stdio.h>
#include <stdlib.h>
#include "pcap.h"
int main( void )
{
pcap_if_t *alldevs = NULL;
char errbuf[PCAP_ERRBUF_SIZE];
/* Retrieve the device list from the local machine */
if (pcap_findalldevs_ex(PCAP_SRC_IF_STRING, NULL /* auth is not needed */, &alldevs, errbuf) == -1)
{
fprintf(stderr,"Error in pcap_findalldevs_ex: %s\n", errbuf);
exit(1);
}
/* Print the list */
for( pcap_if_t *d = alldevs; d != NULL; d= d->next)
{
printf("%d. %s", ++i, d->name);
if (d->description)
printf(" (%s)\n", d->description);
else
printf(" (No description available)\n");
}
if ( ! alldevs )
{
printf("\nNo interfaces found! Make sure WinPcap is installed.\n");
}
/* We don't need any more the device list. Free it */
pcap_freealldevs(alldevs);
}
关于c - GCC在MinGW的stdio.h中发现错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52993896/