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

  • Follow


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';
0
Reply danwgrace (24) 11/8/2009 3:52:05 PM

Daniel wrote:
[ snip ]

> g++  -Wall -g -o0 client.cpp player.cpp  -o tbclient.exe

You're in the wrong room. Try comp.lang.c++

-- 
Joe Wright
"If you rob Peter to pay Paul you can depend on the support of Paul."
0
Reply joewwright (1737) 11/8/2009 4:04:15 PM


"Daniel" <danwgrace@gmail.com> wrote in message
> 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:
>
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.


0
Reply regniztar (3128) 11/8/2009 4:05:06 PM

Daniel wrote:

> Here is the code in question:
>
>   switch (msgtype)
>   {
>     MSG_S_LOGIN_FAIL :

A clear case of a missing 'case'.

-- 
Huibert
"The Commercial Channel! All commercials all the time.
 An eternity of useless products to rot your skeevy little mind, forever!"
   -- Mike the TV (Reboot)
0
Reply huibert.bol (74) 11/8/2009 4:10:20 PM

On 8 Nov, 16:10, Huibert Bol <huibert....@quicknet.nl> wrote:
> Daniel wrote:
> > Here is the code in question:
>
> > =A0 switch (msgtype)
> > =A0 {
> > =A0 =A0 MSG_S_LOGIN_FAIL :
>
> A clear case of a missing 'case'.

ie. try

switch (msgtype)
{
  case MSG_S_LOGIN_FAIL:

you'll probably get a different set of errors

0
Reply nick_keighley_nospam (4574) 11/8/2009 4:14:35 PM

On 8 Nov, 16:05, "Malcolm McLean" <regniz...@btinternet.com> wrote:
>
> 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.

0
Reply danwgrace (24) 11/8/2009 4:20:51 PM

Daniel wrote:
> 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.
-- 
Flash Gordon
0
Reply smap (838) 11/8/2009 4:45:51 PM

On 2009-11-08, Daniel <danwgrace@gmail.com> wrote:
>     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
-- 
Copyright 2009, all wrongs reversed.  Peter Seebach / usenet-nospam@seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
0
Reply usenet-nospam (2199) 11/8/2009 5:30:31 PM

On 2009-11-08, Malcolm McLean <regniztar@btinternet.com> wrote:
> 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
-- 
Copyright 2009, all wrongs reversed.  Peter Seebach / usenet-nospam@seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
0
Reply usenet-nospam (2199) 11/8/2009 5:31:09 PM

Daniel wrote:
> On 8 Nov, 16:05, "Malcolm McLean" <regniz...@btinternet.com> wrote:
>> 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.

I suggest you read the responses by everyone else, since Malcolm is 
wrong about the cause of the problem.
-- 
Flash Gordon
0
Reply smap (838) 11/8/2009 5:52:08 PM

In article <2dc98901-fcbd-4ad6-aba0-c71bfc68ef23@g27g2000yqn.googlegroups.com>,
Daniel  <danwgrace@gmail.com> wrote:

>  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
-- 
Please remember to mention me / in tapes you leave behind.
0
Reply richard91 (3683) 11/12/2009 11:03:50 PM

On 11/13/2009 7:03:47 AM,  wrote:
> In article
> <2dc98901-fcbd-4ad6-aba0-c71bfc68ef23@g27g2000yqn.googlegroups.com>,
> Daniel <danwgrace@gmail.com> wrote:
> 
>>  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".
> 

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.

-- 
--------------------------------------------------------------
Professional mobile software development
BreezySoft Limited www.breezysoft.com
--------------------------------------------------------------
0
Reply lionel (23) 1/19/2010 3:25:54 PM

On 19 Jan, 15:25, "Lionel Pinkhard" <lio...@breezysoft.com> wrote:
> On 11/13/2009 7:03:47 AM, =A0wrote:
>
>
>
>
>
> > In article
> > <2dc98901-fcbd-4ad6-aba0-c71bfc68e...@g27g2000yqn.googlegroups.com>,
> > Daniel <danwgr...@gmail.com> wrote:
>
> >> =A0switch (msgtype)
> >> =A0{
> >> =A0 =A0MSG_S_LOGIN_FAIL :
> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0// TODO
> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0// display msg
> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0//
> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0break;
> >> =A0 =A0 =A0 =A0MSG_S_LOGGED_ON :
> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0// TODO
> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0// start
> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0break;
> >> =A0 =A0 =A0 =A0MSG_S_REG_FAIL :
> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0// TODO
> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0// display msg
> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0break;
> >> =A0 =A0 =A0 =A0MSG_S_REGISTERED :
> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0// TODO
> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0// start
> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0//
> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0break;
> >> =A0}
>
> >>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 contai=
ns
> > no cases".
>
> 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
0
Reply nick_keighley_nospam (4574) 1/19/2010 3:57:27 PM

12 Replies
48 Views

(page loaded in 0.424 seconds)


Reply: