-Wextra is stupid.
It is trying to persuade patterns that ignore the rules of standard C.
In particular for this situation:
Never add extra costs. Adding casts everywhere is HIGHLY ERROR PRONE.
Unneccesary casts were among the hardest parts of the jump from 32-bit
to 64-bit, since a cast means "I know better than the compiler".
Well, when the world changes, that cast is suddenly wrong.
The people adding these things to the compiler are trying to break
the language, leading the user community astray.
> The example proper usage of snprintf(3) (under Caveats) evokes a warning
> when compiled with -Wextra. I presume casting ret to unsigned int would
> be safe, but I'll defer to those who know the nuances.
>
>
> #include<stdio.h>
>
> int
> foo(char* string) {
> char buffer[128];
> int ret = snprintf(buffer, sizeof(buffer), "%s", string);
> if (ret == -1 || ret >= sizeof(buffer))
> return 1;
> return 0;
> }
>
> % cc -c -Wextra foo.c
> foo.c: In function 'foo':
> foo.c:7: warning: comparison between signed and unsigned
>