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

Discussion in 'C Programming' started by Daniel, Nov 8, 2009.

  1. Daniel

    Daniel Guest

    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';
     
    Daniel, Nov 8, 2009
    #1
    1. Advertising

  2. Daniel

    Huibert Bol Guest

    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)
     
    Huibert Bol, Nov 8, 2009
    #2
    1. Advertising

  3. On 8 Nov, 16:10, Huibert Bol <> 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
     
    Nick Keighley, Nov 8, 2009
    #3
  4. Daniel

    Daniel Guest

    On 8 Nov, 16:05, "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.
    >


    Thanks.
     
    Daniel, Nov 8, 2009
    #4
  5. Daniel

    Flash Gordon Guest

    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
     
    Flash Gordon, Nov 8, 2009
    #5
  6. Daniel

    Seebs Guest

    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 /
    http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
    http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
     
    Seebs, Nov 8, 2009
    #6
  7. Daniel

    Seebs Guest

    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 /
    http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
    http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
     
    Seebs, Nov 8, 2009
    #7
  8. Daniel

    Flash Gordon Guest

    Daniel wrote:
    > On 8 Nov, 16:05, "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.

    >
    > Thanks.


    I suggest you read the responses by everyone else, since Malcolm is
    wrong about the cause of the problem.
    --
    Flash Gordon
     
    Flash Gordon, Nov 8, 2009
    #8
  9. In article <>,
    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.
     
    Richard Tobin, Nov 12, 2009
    #9
  10. On 19 Jan, 15:25, "Lionel Pinkhard" <> wrote:
    > On 11/13/2009 7:03:47 AM,  wrote:
    >
    >
    >
    >
    >
    > > In article
    > > <>,
    > > 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".

    >
    > 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
     
    Nick Keighley, Jan 19, 2010
    #10
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Åukasz Ligowski

    "xxx.has_key(a)" vs "a in xxx"

    Åukasz Ligowski, Oct 30, 2008, in forum: Python
    Replies:
    0
    Views:
    297
    Åukasz Ligowski
    Oct 30, 2008
  2. Replies:
    0
    Views:
    1,031
  3. Bert Leu

    value of type "xxx" cannot be converted to "xxx"

    Bert Leu, Jun 5, 2007, in forum: ASP .Net Web Services
    Replies:
    2
    Views:
    297
    Jesse Houwing
    Jun 6, 2007
  4. Richard Lionheart
    Replies:
    4
    Views:
    288
    Richard Lionheart
    May 5, 2004
  5. Iñaki Baz Castillo
    Replies:
    5
    Views:
    154
    Iñaki Baz Castillo
    Mar 30, 2008
Loading...

Share This Page