|
-
June 8th, 2010, 09:21 PM
#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));
-
June 9th, 2010, 11:00 AM
#2
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.
-
June 9th, 2010, 12:22 PM
#3
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
}
-
June 9th, 2010, 02:24 PM
#4
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.
-
June 9th, 2010, 02:39 PM
#5
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/
-
June 10th, 2010, 02:48 AM
#6
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|