I’m looking for solution in the C programming language to remove this warning:
Comparison between signed and unsigned warning
Instead of just do a cast to unsigned in the variable of int type, I thought as the following:
#if MAX_NAME >= INT_MAX
size_t name_size = 0;
#define INT_TYPE size_t
#else
int name_size = 0;
#define INT_TYPE int
#endif
and then:
if(.. && name_size++ >= (INT_TYPE)sizeof(name)) {
//..
}
How do you fix it?
also, suggestions to name of macro INT_TYPE are apprecited too.
Your example is flawed: however you put it you should always use
size_twhen comparing against the result ofsizeof. I.e. there’s no reason to makename_sizeinto anint.As a general note, just use the “natural” signedness for that variable. It boils down to one question: is
name_sizesupposed to ever be negative ?