Q:

comparison between signed and unsigned integer expressions [-Wsign-compare] warning

for ( i= 0; i < sizeof(r)/sizeof(r[0]); ++i ){ 
        r[i]= 0; 
}

So this is the for loop I'm having troubles with, how can I rewrite it so I don't get the warning:
comparison between signed and unsigned integer expressions [-Wsign-compare]

A:

sizeof() returns an unsigned integer of type size_t.  So use an index of the same type.
size_t i;
for (i = 0; i < sizeof(r)/sizeof(r[0]); ++i) { 
  r[i] = 0; 
}

Recommend to not use int size = sizeof(r)/sizeof(r[0]);.  The range of size_t may greatly exceed the positive range of int.  The assignment could then lose significant bits.
size_t is the type best used to index array variables.  Remember, though, since it is some unsigned integer, it can not represent negative indexes.

