Mustafa Khan
Mustafa Khan

Reputation: 47

warning: assignment makes integer from pointer without a cast as return of the function call

char *doRequest(char *start, char**headers, char *body){}

here is my function and I call in this way:

char *response ;
response = doRequest(strt_line, headers, body);

I get this warning:

warning: assignment makes integer from pointer without a cast

How can I correct this?

Upvotes: 0

Views: 197

Answers (1)

Chris Hayes
Chris Hayes

Reputation: 12030

The cause is almost certainly that you have failed to declare doRequest in a way that it is visible before you attempt to call it. Either add a function prototype (the preferred way) or move its definition above the definition of the function which is calling it.

The wrong way:

int main() {
    char *start, *body, **headers;
    doRequest(start, headers, body);
}

char *doRequest(char *start, char**headers, char *body) {
    ...
}

The proper way:

// Function prototype (argument names unnecessary but useful for ease of reading)
char *doRequest(char *start, char**headers, char *body);

int main() {
    char *start, *body, **headers;
    doRequest(start, headers, body);
}

char *doRequest(char *start, char**headers, char *body) {
    ...
}

The reason for this is that when the compiler encounters a function call before it has seen the declaration of the function, it assumes the function's return type is int.

Upvotes: 3

Related Questions