C warning conflicting types

狂风中的少年 提交于 2019-12-30 09:38:18

问题


my code is

void doc(){
          //mycode                
            return;
           }

my warning is

conflicting types for 'doc'

can anybody solve it.


回答1:


In C, if you don't have a prototype for a function when you call it, it is assumed to return an int and to take an unspecified number of parameters. Then, when you later define your function as returning void and taking no parameters, the compiler sees this as a conflict.

Depending upon the complexity of your code, you can do something as simple as moving the definition of the function before its use, or add the function declaration in a header file and include it.

In any case, the net effect should be to make the function prototype available before it is being used.

If you add

void doc(void);

before the function use, you will have a prototype visible in scope, and your warning will go away.

I think this is the most likely cause for your warning. You could have an explicit incompatible declaration of doc in your code, but we can't tell because you have not posted complete code.




回答2:


try writing your doc function before your main function in your program file.




回答3:


u have declared it with some other type/signature and defined with some other type/signature..

like

int doc();
void doc()
{ 
}

will give u this warning.




回答4:


That's clearly not your complete code.

However, that error means that there is another declaration for doc (perhaps a global variable? something in a header file?) that isn't a void function that takes no parameters.




回答5:


"doc" is probably already declared with a different type... you should try to find the previous declaration !




回答6:


You have either declared doc before, or made a call to undeclared doc thus forcing the compiler to deduce a probable parameter declaration for doc from that call. Now, the definition of doc that you quoted is different from that previous declaration (either explicit or deduced by the compiler), which is what is reported as a "conflict".




回答7:


Make sure that you have not used doc any where in your code !, I think that only gives u trouble!




回答8:


Declaring the function above the usage solved it for me.

Example:

void recordAudio(){  //declaration 

    doStuff();
}


void initialise(){ 

    recordAudio();    // usage
}

as you can see above, the usage of recordAudio() is above where is is used.



来源:https://stackoverflow.com/questions/2431242/c-warning-conflicting-types

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!