Page 1 of 1

inaccessible line in switch case? help please o:

PostPosted: Sun Feb 15, 2009 8:32 pm
by Game A Gogo
Alright, so today I though I might as well start on working a project.. and I though why not my Custon BMP Font loader that I had started long ago. That would be able to load custon BMP fonts with individual letter width (Revolutionary! :) )
But obviously, I need to transform the ASCII letter number to the BMP font char number... So I though I'd use a switch case. But I stumbled upon a problem and I can't figure out what is going wrong.. D:
My script is around 288 lines long, because there are at least 90 letters to convert
And the syntax is correct on all lines (Yes, I checked them all).
and it gives me 90 errors!
each one coming out as "Warning line 288: Unreachable code at line ###" ### being the line number which a "break;" can be found
untitled.gif
Image quality severely decreased due to big image size... and yet my screen is not big enough to show all errors :S

So I noticed that each "Unreachable" code are "break;"... what is wrong?
I'm thinking it might be due to the usage of "return ##"... but I used that before

ps.: Makslane, it would be smart adding "*.txt","*.c" and "*.cpp" extension ;)

Re: inaccessible line in switch case? help please o:

PostPosted: Sun Feb 15, 2009 8:50 pm
by skydereign
If you are trying to return an int, then the function should be an int function. I only say this because the last error says that it ends in void. I think gameEditor may be confusing the number conversions, but I don't really know how you are doing this. The problem is that break will end the function, as it exits the switch. Since you are trying to return a char, the int does not work for the return of that function, though I think it should, and the function should then be void, as it does not have a return value. But I know the char numbers shouldn't mess up like this.
-EDIT
Okay, if you change it to this, it should work.
Code: Select all
char Char_Map(char Letter_Input)
{
    char RETURN;
    switch(Letter_Input)
    {
        case 33:
        RETURN=1;
        break;
        case 64:
        RETURN=2;
        break;
    }
return(RETURN);
}

Re: inaccessible line in switch case? help please o:

PostPosted: Sun Feb 15, 2009 9:24 pm
by pyrometal
Remove all the "break" statements! Return breaks the control flow before "break" can be executed!

Re: inaccessible line in switch case? help please o:

PostPosted: Sun Feb 15, 2009 10:54 pm
by Game A Gogo
skydereign wrote:If you are trying to return an int, then the function should be an int function. I only say this because the last error says that it ends in void. I think gameEditor may be confusing the number conversions, but I don't really know how you are doing this. The problem is that break will end the function, as it exits the switch. Since you are trying to return a char, the int does not work for the return of that function, though I think it should, and the function should then be void, as it does not have a return value. But I know the char numbers shouldn't mess up like this.
-EDIT
Okay, if you change it to this, it should work.
Code: Select all
char Char_Map(char Letter_Input)
{
    char RETURN;
    switch(Letter_Input)
    {
        case 33:
        RETURN=1;
        break;
        case 64:
        RETURN=2;
        break;
    }
return(RETURN);
}

About the void thing.. at first it was int xD I messed with the code a bit but thx for trying to help, but I'll use Pyro's method instead, so thanks to you as well, pyro