CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jun 2010
    Posts
    1

    unreachable code

    hey all.

    i got a problem here, im getting a cs0162 unreachable code

    Using NET Framework 2.0.50727

    here is the block its coming from,i commented on the line that is unreachable

    Code:
            public void LabelToAffix(Mobile to, int number, AffixType type, string affix, string args)
            {
                string message = StringList.CombineArguments(number, args);
    
                MessageType label = MessageType.Label;
                if ((type & AffixType.Append) != 0)
                    message += affix; //unreachable
                else
                    message = affix + message;
                if ((type & AffixType.System) != 0)
                    label = MessageType.System;
    
                to.Send(new AsciiMessage(m_Serial, m_ItemID, label, 0x3B2, 3, "", message));

  2. #2
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: unreachable code

    What does AffixType.Append return?

    It would appear that the compiler thinks it always returns 0.

    Is that the case?
    Always use [code][/code] tags when posting code.

  3. #3
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: unreachable code

    If the AffixType is an enum, mark it with the [Flags] attribute and be sure the values are 2's compliment.

    Code:
    [Flags]
    public enum AffixType
    {
      Append = 1,
      System = 2,
      Network = 4
    }

  4. #4
    Join Date
    Jan 2002
    Posts
    87

    Re: unreachable code

    I am not sure if this will resolve your problem but since "&" operator works on "integral types" try casting your variables into one of those, i.e. try:
    Code:
    if (((int) type & (int) AffixType.Append) != 0)
    instead of the if statement that you had before.

    Let me know if it worked.

  5. #5
    Join Date
    Jun 2008
    Posts
    2,477

    Re: unreachable code

    You don't need to cast an enum (if that's what this is) to use bitwise operators on it. You don't eevn need to use the Flags attribute, you just need to make sure that each value is a power of 2.
    If you liked my post go ahead and give me an upvote so that my epee.... ahem, reputation will grow.

    Yes; I have a blog too - http://the-angry-gorilla.com/

  6. #6
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    Re: unreachable code

    I think AffixType.Append = 0 (it could be if it is the first element of enum and you don't specify values like Arjay sugest), than anything & 0 is always 0, which cannot differ from zero, so the condition cannot be satisfied in any way.
    • Make it run.
    • Make it right.
    • Make it fast.

    Don't hesitate to rate my post.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured