Comparing unsigned type with type sign

My compiler (DSP SHARC) is very picky. When I build with comments, I get this error:

[cc1123] foo.c:1511 {D} remark: comparison of unsigned type
          with signed type
      while (taille > 0)

Two solutions:

  • The compiler is right and I have to write

    size_t taille;
    ...
    while(taille > (size_t)0)
    
  • The compiler is stupid and I have to ignore this remark

  • Another solution that may include ISO or MISRA standards

What should I do with this remark?

EDIT

In fact, it’s better to write this example, for example

 while(taille) {...}

But this is not related to my initial question.

+4
source share
1 answer

IMO, the compiler is weak or at least pedantic. To appease this unnecessary warning, use:

while (taille > 0u) 

By the way: love the "two solutions: 1. 2. and 3".


Late credit: now see @Wintermute commented on this earlier than me.

+4

All Articles