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

前端 未结 5 1242
野性不改
野性不改 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条回答
  •  庸人自扰
    2020-12-12 00:10

    consider this loop:

    for(unsigned int i=5;i>=0;i--)
    {
    
    }
    

    This loop will be infinite because whenever i becomes -1 it'll be interprated as a very large possitive value as sign bit is absent in unsigned int.

    This is the reason a warning is generated here

提交回复
热议问题