Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the "different width due to prototype" warning mean?

The code generating the warning, passing argument 1 of 'isHex' with different width due to prototype:

/* Checks if a character is either 0-9 or A-F */
int isHex(char ch) {
    return isdigit(ch) || (ch >= 65 && ch <= 70);
}

/* Checks if a string only contains numeric characters or A-F */
int strIsHex(char * str) {
    char *ch;
    size_t len = strlen(str);
    for(ch=str;ch<(str+len);ch++) {
        if (!isHex(*ch)) return 0;
    }
    return 1;
}

What does this mean, shouldn't the char values be the be same width? How can I cast them to the same width to prevent this warning?

By the way, the gcc command was: gcc.exe -std=c99 -fgnu89-inline -pedantic-errors -Wno-long-long -Wall -Wextra -Wconversion -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -fshort-enums -gstabs -l"C:\program files\quincy\mingw\include" -o main.o -c main.c

I can't remove any of the warning options from gcc as one of the marking criteria for an assignment is that there are no errors or warnings with this command.

Thanks.

like image 855
Adam M-W Avatar asked Apr 01 '11 05:04

Adam M-W


1 Answers

This is due to the -Wconversion flag on the command line. It pops up "if a prototype causes a type conversion that is different from what would happen to the same argument in the absence of a prototype." Since the default integral argument type is int, you can't declare isHex(char ch) without triggering this.

You have two options, I think: declare isHex(int ch) and let it be widened in the call or else declare it isHex(char *ch) and change the call.

P.S. If this is homework, it should be tagged as such.

like image 96
Ted Hopp Avatar answered Sep 22 '22 16:09

Ted Hopp