Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the meaning of the GCC warning "case label value exceeds maximum value for type"?

My code looks like this:

char * decode_input(char ch)
{
        switch(ch) {
                case 'g':
                        return "get";
                        break;
                case KEY_F(9):
                        return "quit";
                        break;
                default:
                        return "unknown";
                        break;
        }
}

Any clues?

like image 863
Alistair Avatar asked Jun 18 '09 05:06

Alistair


2 Answers

Well, KEY_F(9) would be 273 (see curses.h) which exceeds the range of char (-128,127).

like image 192
Kousik Nandy Avatar answered Sep 23 '22 01:09

Kousik Nandy


A char is a number between -128 and 127. KEY_F(9) probably is a value outside of that range.

Use:

  • unsigned char, or
  • int, or
  • (char) KEY_F(9)

Or even better, use a debugger and determine sizeof(KEY_F(9)) to make sure it's a byte and not a short.

like image 40
razzed Avatar answered Sep 22 '22 01:09

razzed