简体   繁体   English

53:6:警告:功能类型冲突

[英]53:6: warning: conflicting types for function

#include <stdio.h>
#include <string.h>
struct students{
    char name[50];
    int age;
    int height;
};

int main(int argc, char **argv)
{
    struct students manoj;

    strcpy(manoj.name, "manojkumar");
    manoj.age = 15;

    displaymanoj(&manoj); //print testing \n , name , age 

    return 0;
}

void displaymanoj(struct students *ptr) {
    printf("Testing...............DEBUG\n");
    printf("%s\t%d\n", ptr->name,ptr->age);
    printf("END OF TEST: SUCESS -manoj-");
}

I am learning C and it's working where is use pointer to point to structure variable. 我正在学习C,并且在哪里使用指向结构变量的指针起作用。 I am getting the correct output when I run the program. 运行程序时,我得到正确的输出。 Just that my Geany IDE giving out some message which I would like to know why. 只是我的Geany IDE发出了一些我想知道原因的消息。

My Compiler Message as below : 我的编译器消息如下:

You must declare the functions before calling them. 您必须在调用函数之前声明它们。

So your program should look something like 所以你的程序应该看起来像

// Includes
// Structure

// Function prototype declaration
// This was what you were missing before
void displaymanoj(struct students *ptr);

int main(int argc, char **argv)
{
    ...
}

void displaymanoj(struct students *ptr) {
    ...
}

Since you have the definition of displaymanoj() isn't seen when you call it from main() , compiler implicitly declares one with return type int which conflicts with the actual one. 由于您具有在从main()调用displaymanoj()时看不到的定义, displaymanoj()编译器隐式声明一个返回类型为int显示类型,该返回类型与实际的类型冲突。 Note that the implicit declaration has been removed since the C99 standard and is no longer valid. 请注意,自C99标准以来, 隐式声明已删除,并且不再有效。

To fix it: 要解决这个问题:

1) Either move the function displaymanoj() above main()'s definition or 1)将函数displaymanoj()移到main()的定义上方,或者
2) Do a forward declaration of displaymanoj() . 2)对displaymanoj()进行前向声明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM