This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
-Wformat-sign-mismatch?
- From: Dan Kegel <dkegel at ixiacom dot com>
- To: gcc at gcc dot gnu dot org
- Cc: Jake Holland <jholland at ixiacom dot com>
- Date: Mon, 10 Feb 2003 12:08:59 -0800
- Subject: -Wformat-sign-mismatch?
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;
}