Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > what does it mean: warning: label `xxx' defined but not used

Reply
Thread Tools

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

 
 
Daniel
Guest
Posts: n/a
 
      11-08-2009
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';
 
Reply With Quote
 
 
 
 
Huibert Bol
Guest
Posts: n/a
 
      11-08-2009
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)
 
Reply With Quote
 
 
 
 
Nick Keighley
Guest
Posts: n/a
 
      11-08-2009
On 8 Nov, 16:10, Huibert Bol <huibert....@quicknet.nl> wrote:
> Daniel wrote:
> > Here is the code in question:

>
> > * switch (msgtype)
> > * {
> > * * 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

 
Reply With Quote
 
Daniel
Guest
Posts: n/a
 
      11-08-2009
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.

 
Reply With Quote
 
Flash Gordon
Guest
Posts: n/a
 
      11-08-2009
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
 
Reply With Quote
 
Seebs
Guest
Posts: n/a
 
      11-08-2009
On 2009-11-08, Daniel <> 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-
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
 
Reply With Quote
 
Seebs
Guest
Posts: n/a
 
      11-08-2009
On 2009-11-08, Malcolm McLean <> 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-
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
 
Reply With Quote
 
Flash Gordon
Guest
Posts: n/a
 
      11-08-2009
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
 
Reply With Quote
 
Richard Tobin
Guest
Posts: n/a
 
      11-12-2009
In article <2dc98901-fcbd-4ad6-aba0->,
Daniel <> 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.
 
Reply With Quote
 
Nick Keighley
Guest
Posts: n/a
 
      01-19-2010
On 19 Jan, 15:25, "Lionel Pinkhard" <lio...@breezysoft.com> wrote:
> On 11/13/2009 7:03:47 AM, *wrote:
>
>
>
>
>
> > In article
> > <2dc98901-fcbd-4ad6-aba0-c71bfc68e...@g27g2000yqn.googlegroups.com>,
> > Daniel <danwgr...@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.


no. read the other posts
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Defined but not used? But I am using it! Travis C++ 6 06-28-2007 08:23 PM
#if (defined(__STDC__) && !defined(NO_PROTOTYPE)) || defined(__cplusplus) Oodini C Programming 1 09-27-2005 07:58 PM
Warning about defined but not used for global variable Eric Lilja C++ 3 01-30-2005 05:22 PM
Warning: Defined but not used William Payne C++ 3 02-20-2004 08:45 PM
'NODE' is used as a type, but has not been defined as a type Kabeer C++ 6 08-21-2003 03:54 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57