Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Warning: Unreachable code at begining of swich

Status
Not open for further replies.

prasadraon

Programmer
Apr 2, 2003
2
US
can anybody help me the cause of this warning..it works fine on AIX box and throws me the above error on LINUX box.
thanks in advance
 
Sure.
It's a compiler complaining about your code.
Does that help you?
If not consider posting the code next time.

 
The compiler on your Linux box is complaining about unreachable code. That's code that can't be reached.

The compiler on your AIX box doesn't complain. It's content to let you make that mistake.

Perhaps the code can't be reached because the code doesn't belong to a case. Without seeing any code, how do you expect anyone to tell?
 
Check the spelling of default. This is the most common error I've seen for switch statements

Code:
switch (x)
{
case 'A': ...

case 'B': ...

defualt: ...
}

defualt is taken as a label and as such is not an error. Nothing goes to it so it is unreachable.
 
Sorry - you mentioned at the beginning. It is probably something like
Code:
switch (x)
{
   // Unreachable code

case 'A':...

etc
}
 
a) defualt is default
b) switch works with integer values, what's 'x' ?
 
x is anything that can be switched on: char, int, long, unsigned, long long etc.

If you spell default incorrectly as defualt, the compiler will not give an error as it is a legal label.
 
Sometimes the 'case' statement is forgotten also. When using symbols instead of values, these are interpreted as labels also.

Code:
switch(x)
{
FIRST:

SECOND:

THIRD:

default:
}
 
The condition at the beginning of the switch is never true or will never be processed as coded.

toncruz.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top