This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

-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;
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]