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++ > 4 byte align

#113930 - rodif - Mon Jan 01, 2007 7:48 am

So I got bit by this issue, searching the forums i found your faq that talks about this.
Quote:
Also, make sure that both your map data, your tile data, and your palette data are aligned to a 4-byte boundary within your binary. If you use assembly language, put .balign 4 on a line before the data; in C do this (recommended only for smaller arrays such as palette data):
__attribute__((aligned(4))) const char foo[8192] = { /*...*/ };
Aligns the start of the array to a 4-byte boundary.



My problem is i had const strings in my file and based on the string length it would screw up my sprites and background.
Code:
doSomething("text");


After I realized what the problem was, I could fix it by simply declaring the string as a
Code:
const char text[] = "text";

and everything worked.

EDIT:
sorry i just realized what I was doing, i was missing a "__attribute__((aligned(4))) " for my sprite data declaration, I had them on my tile data but missed it for my sprite.

#113931 - sgeos - Mon Jan 01, 2007 8:20 am

rodif wrote:
i just realized what I was doing, i was missing a "__attribute__((aligned(4))) " for my sprite data declaration, I had them on my tile data but missed it for my sprite.

It happens. Best of luck!

-Brendan