gcc编程出错警告汇总(持续更新)
- 警告:将一个指针转换为大小不同的整数 [-Wpointer-to-int-cast]
printf(“print the address of a :%u ”, (unsigned int)&a);
我的环境是64位的,所以指针大小是8字节的,所以将unsigned int 换成 unsigned long即可。 - network.c: 在函数‘main’中:
network.c:38:20: 错误:‘CLONE_NEWNET’未声明(在此函数内第一次使用)
int clone_flags = CLONE_NEWNET | SIGCHLD;
解决方案:添加头文件
#define _GNU_SOURCE
#include <sched.h>
- hello.c:12:19: 警告:隐式声明与内建函数‘malloc’不兼容 [默认启用]
解决方案:添加头文件stdlib,malloc的声明在stdlib中。 - error.c:71:3: 警告:隐式声明与内建函数‘snprintf’不兼容 [默认启用]
snprintf(buf + n, MAXLINE - n, “:%s”, strerrno(errno_save));
这种警告一般都是缺少头文件 - gcc -o daytimetcpsrv1 daytimetcpsrv1.c wrapsock.c error.c -std=c99
daytimetcpsrv1.c: 在函数‘main’中:
daytimetcpsrv1.c:36:3: 警告:隐式声明函数‘Close’ [-Wimplicit-function-declaration]
Close(connfd);
^
wrapsock.c: 在函数‘Write’中:
wrapsock.c:52:2: 警告:隐式声明函数‘write’ [-Wimplicit-function-declaration]
if(write(fd, ptr, nbytes) != nbytes)
^
wrapsock.c: 在函数‘Read’中:
wrapsock.c:59:2: 警告:隐式声明函数‘read’ [-Wimplicit-function-declaration]
if( -1 == (n = read(fd, ptr, nbytes)))
^
wrapsock.c: 在函数‘Close’中:
wrapsock.c:67:2: 警告:隐式声明函数‘close’ [-Wimplicit-function-declaration]
if(-1 == close(fd))
^
原因在用-std=c99的时候出现了更多的警告,解决方案去掉
-std=c99,并去掉c语言中的,局部定义方法。
声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。