-Wformat-sign-mismatch?
Dan Kegel
dkegel@ixiacom.com
Mon Feb 10 20:16:00 GMT 2003
At our company, Gimpel's PC-Lint flagged an warning
in code similar to this:
unsigned long iResult;
sscanf(s, "%ld", &iResult);
Do we want gcc to detect such mismatches, too?
I don't think it could as of the gcc 3.2 I tried.
If this is something gcc should be checking,
it might be good to let users control this warning
independently of other -Wformat warnings
(e.g. with a new option -Wformat-sign-mismatch).
- Dan
#include <stdio.h>
int main(int argc, char **argv)
{
unsigned long iResult;
int result = 1;
/* This does not trigger any warning in gcc <= 3.2 (20020903 from rh8),
* but does trigger a warning in Gimpel's PC-Lint
*/
sscanf(argv[1], "%ld", &iResult);
/* Trigger -Wformat */
sscanf(argv[1], "%s", &iResult);
/* Trigger -Wsign-mismatch */
if (result != iResult)
printf("Not equal to 1\n");
return (int) iResult;
}
More information about the Gcc
mailing list