warning: comparison of unsigned expression >= 0 is always true

前端 未结 5 1250
野性不改
野性不改 2020-12-11 23:23

I have the following error when compiling a C file:

t_memmove.c: In function ‘ft_memmove’:
ft_memmove.c:19: warning: comparison of unsigned expression >=          


        
5条回答
  •  旧时难觅i
    2020-12-11 23:54

    According to section 6.3.1.8 of the draft C99 standard Usual arithmetic conversions, since they are both of the same type, the result will also be size_t. The section states:

    [...]Unless explicitly stated otherwise, the common real type is also the corresponding real type of the result[...]

    and later on says:

    If both operands have the same type, then no further conversion is needed.

    mathematically you can just move the i over to the other side of the expression like so:

     n >= i
    

提交回复
热议问题