Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C warning conflicting types

Tags:

c

warnings

my code is

void doc(){
          //mycode                
            return;
           }

my warning is

conflicting types for 'doc'

can anybody solve it.

like image 225
ambika Avatar asked Mar 12 '10 07:03

ambika


2 Answers

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.

like image 111
Alok Singhal Avatar answered Oct 02 '22 23:10

Alok Singhal


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

like image 33
swapnil Avatar answered Oct 02 '22 23:10

swapnil