小编Dad*_*m42的帖子

对理解和消除 -Wsign-compare gcc 的警告感到困惑

这是我正在尝试编译的函数:

static ssize_t  output(t_out_buffer *buf, char const *src, size_t size)
{
        size_t  osize;

        osize = size;
        while ((size > 0)
               && (size -= write(buf->fd, src, size) < osize))
        {
                src += osize - size;
                buf->count +=  osize - size;
                osize = size;
        }
        if (osize < size)
                return (T_OUT_BUFFER_ERROR);
        else
                return (buf->count);
}
Run Code Online (Sandbox Code Playgroud)

和 gcc 的抱怨:

t_out_buffer.c:11:42: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    && (size -= write(buf->fd, src, size) < osize))
                                          ^
Run Code Online (Sandbox Code Playgroud)

我认为 as sizeis unsigned, …

c unsigned compiler-warnings

3
推荐指数
1
解决办法
85
查看次数

标签 统计

c ×1

compiler-warnings ×1

unsigned ×1