【问题标题】:warning: passing argument 2 of ‘accept’ from incompatible pointer type [-Wincompatible-pointer-types]警告:从不兼容的指针类型 [-Wincompatible-pointer-types] 传递“接受”的参数 2
【发布时间】:2020-09-24 05:04:47
【问题描述】:

我收到警告:从不兼容的指针类型 [-Wincompatible-pointer-types] 传递“接受”的参数 2

为什么会出现这个错误?

        if(s = accept(ls, &client_address, &client_address_len)<0);
        {
            perror("Error: accepting failed!!");
            exit(1);
        }

【问题讨论】:

  • client_address 是如何定义的?

标签: c tcp client-server tcplistener


【解决方案1】:

根据https://pubs.opengroup.org/onlinepubs/009695399/functions/accept.htmlaccept函数的第二个参数接收到struct sockaddr *的类型。您可能想要进行转换:&amp;client_address(struct sockaddr *)&amp;client_address

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-09
    • 2011-01-10
    • 2020-07-29
    • 2019-10-14
    相关资源
    最近更新 更多