This is the mail archive of the gcc-bugs@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]

warnings with char type and -Wconversion


[Please cc replies and follow-ups to me, I do not subscribe to the list]

With the -Wconversion switch, gcc warns that the arg passed to
PrintChar(char c) is a different width, but it *is* a char.  

If `c' is declared as an int and the function is also changed to
PrintChar(int c) then this warning is not generated, and a warning is
issued about passing unsigned `uc' to the function (expected behaviour).

Also, gcc fails to warn about comparing an unsigned char with 256
whereas it does issue a warning for the signed char type.

I am using the DJGPP port of gcc v2.95.2

Here is the test code, see below for compile results:

/* warnbug.c - compile: gcc -Wall -Wconversion warnbug.c -o warnbug
*/

#include <stdio.h>

void PrintChar(char c);

int main(void) 
{
    char c;
    unsigned char uc;
    
    /* Infinite loop, gcc warns about this one */
    for (c=0; c<256; c++)
        PrintChar(c); /* gcc says arg 1 is different width */
        
    /* Infinite loop, gcc does not warn about this one */
    for (uc=0; uc<256; uc++)
        PrintChar(uc); /* gcc says arg 1 is different width,
                          and fails to tell about sign change */
    return 0;
}

void PrintChar(char c) 
{
    printf("c=%d\n", c);
}

/*** end of file- warnbug.c ***/


~/test $ gcc -Wall -Wconversion warnbug.c -o warnbug
warnbug.c: In function `main':
warnbug.c:14: warning: comparison is always true due to limited range of data ty
pe
warnbug.c:15: warning: passing arg 1 of `PrintChar' with different width due to
prototype
warnbug.c:19: warning: passing arg 1 of `PrintChar' with different width due to
prototype

~/test $ gcc -v
Reading specs from d:/djgpp/lib/gcc-lib/djgpp/2.952/specs
gcc version 2.95.2 19991024 (release)


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