gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

C/C++ > Branch out of range... again! (fixed, sorta)

#43946 - MrD - Sat May 28, 2005 3:48 pm

Hi folks,

I've been making a small GBA game in C without too many troubles (thanks to y'all =D) but recently I've been getting a lot of 'branch out of range' assembler errors when I try to compile.

This error happened before, so I looked it up and I replaced some of my switches with if's and else's and that seemed to chase it off. Unfortunately, it seems to have come back. ._.

I've looked this up on the search and it seems that this is because the ASM generated from the C is trying to jump across to far a code gap, or something suchly... Anybody got any suggestions on how I can try to eliminate this error?

The only way I've managed to fix it this last time is to disable -funroll-loops... which I don't really wanna do.

Edit - Recompilation with -mlong-calls results in a whole lot of 'invalid offset: value too big (0x00000403)' asm errors.

Edit 2 - Ladies and gentlemen, I'd like to reiterate: switch has some serious issues.

I found another one of the evil switches hiding around some lesser seen and assumed perfect code and blasted it to elses. now everything is back to fun!

#43951 - poslundc - Sat May 28, 2005 5:04 pm

If your switch statements are too long/complicated for the compiler to generate correct assembly code, consider refactoring some of the case-code into function calls.

Dan.

#43955 - MrD - Sat May 28, 2005 5:39 pm

Function calls?!!!?11! One one one one one!!

Okie doke, I'll give it a shot. :)

I don't know what was up with it... all that was in there was a one line allocation switching the players direction variable and incrementing appropriate coordinates. Ah well. S'all good now. Cheers! :)

#43957 - poslundc - Sat May 28, 2005 5:51 pm

MrD wrote:
I don't know what was up with it... all that was in there was a one line allocation switching the players direction variable and incrementing appropriate coordinates. Ah well. S'all good now. Cheers! :)


Wow, it sounds pretty messed up if your code is that simple. I know that in Thumb mode the worst-case branch instruction can only jump ahead about 128 instructions, but I would think that the compiler would be smart enough not to use it for that kind of thing.

Are you using the latest DevkitARM? If not, perhaps upgrading to a newer version of GCC will fix this problem.

Dan.