【问题标题】:Failure comparison between pointer and integer [closed]指针和整数之间的失败比较[关闭]
【发布时间】:2016-04-19 13:46:33
【问题描述】:

我有一个函数是:

int accept_connection(void);

如果它返回负数,我会尝试做一个错误声明,并且我会收到指针和整数之间比较的警告。

这是我写的:

pthread_t dis;
if(accept_connection == -1){
    fprintf(stderr, "Failed to accept connection\n");
    pthread_exit(&dis);

【问题讨论】:

  • 编译时启用所有警告。

标签: c pointers pthreads


【解决方案1】:

在您的代码中

  if(accept_connection == -1)

试图检查函数指针,而不是函数返回值。这就是编译器对你大喊大叫的原因。

您需要改为调用函数并使用返回值 (int)。使用

if( accept_connection() == -1 )

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多