【问题标题】:c - warning: implicit declaration of function ‘printf’c - 警告:函数‘printf’的隐式声明
【发布时间】:2012-12-13 16:51:00
【问题描述】:

我知道之前有人问过很多类似的问题,但我找不到可以解决这个警告的方法:

MyIntFunctions.c:19:2: warning: implicit declaration of function ‘printf’ [-Wimplicit-function-declaration]

在这里发生:

void IntPrint (const void *key)
{
    printf("%d", *(int*)key); // line 19
    printf("\t-->\t");
}

以及类似的警告:

MyStringFunctions.c:22:2: warning: implicit declaration of function ‘printf’ [-Wimplicit-function-declaration]

void StringPrint (const void *key)
{
    printf("%s",(char*)key); //line 22
    printf("\t-->\t");
}

我真的很想知道哪里出了问题,所以我以后不会再这样做了。

【问题讨论】:

  • 你考虑过加入<stdio.h>
  • 请告诉我们如何包含头文件。

标签: c


【解决方案1】:

您需要包含适当的标题

#include <stdio.h>

如果您不确定标准函数定义在哪个标头中,函数的man page 会说明这一点。

【讨论】:

    【解决方案2】:

    您需要包含printf() 函数的声明。

    #include <stdio.h>
    

    【讨论】:

      【解决方案3】:

      IMPLICIT DECLARATION 类型的警告或错误是编译器需要一个函数声明/原型..

      它可能是一个头文件或你自己的函数声明..

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-01-16
        • 1970-01-01
        相关资源
        最近更新 更多