what does it mean: warning: label `xxx' defined but not used

D

Daniel

Here is the code in question:

switch (msgtype)
{
MSG_S_LOGIN_FAIL :
// TODO
// display msg
//
break;
MSG_S_LOGGED_ON :
// TODO
// start
break;
MSG_S_REG_FAIL :
// TODO
// display msg
break;
MSG_S_REGISTERED :
// TODO
// start
//
break;
}

....and here are the warnings:

$ make
g++ -Wall -g -o0 client.cpp player.cpp -o tbclient.exe
client.cpp: In member function `void TClient::RecvMsg()':
client.cpp:69: warning: label `MSG_S_REGISTERED' defined but not used
client.cpp:65: warning: label `MSG_S_REG_FAIL' defined but not used
client.cpp:61: warning: label `MSG_S_LOGGED_ON' defined but not used
client.cpp:56: warning: label `MSG_S_LOGIN_FAIL' defined but not used

Here are the declarations:

const char MSG_S_LOGIN_FAIL = 'l';
const char MSG_S_LOGGED_ON = 'L';
const char MSG_S_REG_FAIL = 'r';
const char MSG_S_REGISTERED = 'R';
 
D

Daniel

The compiler doesn't realise that this is skeleton code. Since you don't do
anything, yet, in the switch, the labels are pointless and it is warning you
about that.

Thanks.
 
F

Flash Gordon

Daniel said:
Here is the code in question:

switch (msgtype)
{
MSG_S_LOGIN_FAIL :
// TODO
// display msg
//
break;
MSG_S_LOGGED_ON :
// TODO
// start
break;
MSG_S_REG_FAIL :
// TODO
// display msg
break;
MSG_S_REGISTERED :
// TODO
// start
//
break;
}

....and here are the warnings:

It would be easier if you put your question in the body of the message,
not just in the subject line. You were asking about what these warnings
mean...
$ make
g++ -Wall -g -o0 client.cpp player.cpp -o tbclient.exe
client.cpp: In member function `void TClient::RecvMsg()':
client.cpp:69: warning: label `MSG_S_REGISTERED' defined but not used
client.cpp:65: warning: label `MSG_S_REG_FAIL' defined but not used
client.cpp:61: warning: label `MSG_S_LOGGED_ON' defined but not used
client.cpp:56: warning: label `MSG_S_LOGIN_FAIL' defined but not used

It's quite simple, it means that you have defined those labels but not
actually used them! You just think you've used them, but you are wrong!
For "switch labels", you need to use the "case" keyword, i.e.
case MSG_S_REGISTERED:
By not including the "case" keyword you have created "goto labels".
Here are the declarations:

const char MSG_S_LOGIN_FAIL = 'l';
const char MSG_S_LOGGED_ON = 'L';
const char MSG_S_REG_FAIL = 'r';
const char MSG_S_REGISTERED = 'R';

However, with those definitions I would not expect it to work in C!
Possibly C++, but that is a different language discussed in comp.lang.c++

In C I would expect you to use
#define MSG_S_LOGIN_FAIL 'l'
etc.
The reason being that in C using const does not give you a compile time
constant.
 
S

Seebs

MSG_S_LOGIN_FAIL :

This is a goto label, which you never goto.

Maybe you wanted a "case" statement, in which case, it'd be written:

case MSG_S_LOGIN_FAIL:

-s
 
S

Seebs

The compiler doesn't realise that this is skeleton code. Since you don't do
anything, yet, in the switch, the labels are pointless and it is warning you
about that.

Either you're joking or you missed the point badly. I can't tell which.

-s
 
R

Richard Tobin

Daniel said:
switch (msgtype)
{
MSG_S_LOGIN_FAIL :
// TODO
// display msg
//
break;
MSG_S_LOGGED_ON :
// TODO
// start
break;
MSG_S_REG_FAIL :
// TODO
// display msg
break;
MSG_S_REGISTERED :
// TODO
// start
//
break;
}
client.cpp: In member function `void TClient::RecvMsg()':
client.cpp:69: warning: label `MSG_S_REGISTERED' defined but not used
client.cpp:65: warning: label `MSG_S_REG_FAIL' defined but not used
client.cpp:61: warning: label `MSG_S_LOGGED_ON' defined but not used
client.cpp:56: warning: label `MSG_S_LOGIN_FAIL' defined but not used

A helpful compiler would also give the warning "switch statement contains no
cases".

-- Richard
 
N

Nick Keighley

Pretty normal, given that your labels aren't doing anything (i.e. "not
used"), // TODO is not considered a statement, all the compiler sees is
break.

no. read the other posts
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top