TomSelleck
TomSelleck

Reputation: 6968

Assignment makes integer from pointer without a cast warning

Can anybody explain why the following code gives the following warning and how to remedy it?

warning: assignment makes integer from pointer without a cast [enabled by default]

Here is the code:

int tcp_socket(void)
{
    int s;

    if ((s = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
        _logf(LOG_DEBUG, "LOG %s:%d (%s) - %s", __FILE__, __LINE__, __func__, "Error creating socket");
        return -1;
    }
    return s;       
}

int main(int argc, char **argv)
{
    int socket;
    socket = tcp_socket;
    if(socket == -1) {
        _logf(LOG_INFO, "LOG %s:%d (%s) - %s", __FILE__, __LINE__, __func__, "Error creating socket, exiting...");
        exit(-1);
    } 
}

Upvotes: 0

Views: 3538

Answers (1)

0xF1
0xF1

Reputation: 6116

Correct this:

socket = tcp_socket;

to

socket = tcp_socket();

tcp_socket() is a function call, while tcp_socket is a pointer to the function location in memory.

Upvotes: 8

Related Questions