这是我第一次使用 Eclipse 编写 C 代码,所以答案可能非常简单。我还认为 Eclipse 已经设置为可以适本地编译、构建和链接。这是在 Windows 7 64 位机器上运行的。
在我的 C 代码中,似乎每当我使用 malloc()
甚至 printf()
函数时,它都会在其下方放置红色波浪线。只有函数有下划线,而不是转换甚至参数。
代码行如下:
#include <stdlib.h>
#include <stdio.h>
int* list; //This is a global variable
int main(){
//...inside a function
list = (int*) malloc( sizeof(int) ); // Out of this line, only the word "malloc" is underlined in red.
printf(""); //printf also gives me an error
return 0;
}
当我将鼠标悬停在错误上时,它会显示以下内容:
Function 'malloc' could not be resolved.
我使用的是 malloc()
吗?
最佳答案
您没有提供足够的信息。您需要提供一个完整的程序,包括 malloc
,无论多么小,都无法编译。您还需要给出您遇到的编译器错误,以及问题是出在 malloc
上还是出在所有标准库函数上。
据推测,您的编译器软件安装不正确,无法找到 stdlib.h
。
正如您现在添加的那样,没有标准库函数起作用,您的编译器设置肯定存在问题(这与 malloc
无关)。
关于c - 使用 Eclipse 在 C 中使用 malloc() 和其他函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15258926/