Getting "conflicting types for function" in C, why?

Viewed 334298

I'm using the below code:

char dest[5];
char src[5] = "test";

printf("String: %s\n", do_something(dest, src));

char *do_something(char *dest, const char *src)
{
    return dest;
}

The implementation of do_something is not important here. When I try to compile the above I get these two exception:

error: conflicting types for 'do_something' (at the printf call)
error: previous implicit declaration of 'do_something' was here (at the prototype line)

Why?

11 Answers

Make sure that types in the function declaration are declared first.

/* start of the header file */
.
.
.
struct intr_frame{...}; //must be first!
.
.
.
void kill (struct intr_frame *);
.
.
.
/* end of the header file */

#include <arpa/inet.h>

for objective-c Conflicting types for 'inet_ntoa'

Related