我有一个小程序来测试函数内外传递char*指针。
当我使用cc编译时,我会收到警告和错误,说我有冲突的类型,即使我的所有变量都是char*请开导

#include <stdio.h>

main()
{
    char* p = NULL;

    foo1(p);
    foo2();
}

void foo1(char* p1)
{
}

char* foo2(void)
{
    char* p2 = NULL;

    return p2;
}

p.c:11: warning: conflicting types for ‘foo1’
p.c:7: warning: previous implicit declaration of ‘foo1’ was here
p.c:15: error: conflicting types for ‘foo2’
p.c:8: error: previous implicit declaration of ‘foo2’ was here

最佳答案

您需要在main()函数之前对函数进行原型化。
例子:

void foo1(char *p1);
char* foo2(void);

int main(.......

或者把这些功能的主体放在主功能之上。

关于c - 与char冲突的类型*,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/885801/

10-11 22:49
查看更多