tags:

views:

273

answers:

7

my code is

void doc(){
          //mycode                
            return;
           }

my warning is

conflicting types for 'doc'

can anybody solve it.

+2  A: 

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.

Greg Hewgill
he also may have used the function before its definition
Carson Myers
Yes, good catch. Still, not complete code. :)
Greg Hewgill
+1  A: 

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.

echo
+1  A: 

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

jag
+3  A: 

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.

Alok
+1  A: 

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".

AndreyT
+1  A: 

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

abubacker
A: 

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

swapnil