Kre*_*dns 108 c malloc gcc warnings sizeof
如果我malloc在我的代码中使用:
int *x = malloc(sizeof(int));
Run Code Online (Sandbox Code Playgroud)
我收到以下警告gcc:
new.c:7: warning: implicit declaration of function ‘malloc’
new.c:7: warning: incompatible implicit declaration of built-in function ‘malloc’
Run Code Online (Sandbox Code Playgroud)
sep*_*p2k 222
你需要添加:
#include <stdlib.h>
Run Code Online (Sandbox Code Playgroud)
该文件包含内置函数的声明malloc.如果你不这样做,编译器认为你想定义你自己的命名函数malloc,它会警告你,因为:
int不兼容) in malloc,取a size_t并返回a void*).and*_*dri 16
您需要包含声明该函数的头文件,例如:
#include <stdlib.h>
Run Code Online (Sandbox Code Playgroud)
如果不包含此头文件,则编译器不知道该函数.所以它认为它是未宣布的.
Tim*_*oft 10
养成在帮助中查找功能的习惯.
C的大多数帮助都是在unix手册页上建模的.
男人malloc
给出非常有用的结果.
谷歌搜索manoc将告诉你我的意思.
当然,在unix中你也可以得到相关的东西.
| 归档时间: |
|
| 查看次数: |
95781 次 |
| 最近记录: |