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.

Coding > u32's re-ordered when compling using devkitadv .. help ! :)

#15046 - cosmic4z - Fri Jan 16, 2004 4:21 pm

I have 8, u32 (long) values in my c, source file, thus:

long CAM_p1_x; // top left (x)
long CAM_p1_y; // top left (y)
long CAM_p2_x; // top right (x)
long CAM_p2_y; // top right (y)
long CAM_p3_x; // bottom left (x)
long CAM_p3_y; // bottom left (y)
long CAM_p4_x; // bottom right (x)
long CAM_p4_y; // bottom right (y)

When I complie my project (using devkitadv), I look in the generated mapfile and they do not appear in the same order in memory as specified in my source file.

The relevant part of the map file, looks like this:

COMMON 0x03000888 0x40 camera.o
0x0 (size before relaxing)
0x03000888 CAM_p3_y
0x0300088c CAM_p1_y
0x03000890 CAM_right_y
0x03000894 CAM_left_x
0x03000898 CAM_p4_y
0x0300089c CAM_p2_x
0x030008a0 CAM_p4_x
0x030008a4 CAM_right_x
0x030008a8 CAM_p3_x
0x030008ac CAM_p1_x
0x030008b0 CAM_top_x
0x030008b4 CAM_bottom_y
0x030008b8 CAM_p2_y
0x030008bc CAM_left_y
0x030008c0 CAM_bottom_x
0x030008c4 CAM_top_y

As you can see, the order has been mixed up.

Why is this, and is there anything I can do to force the same order as per my source file?

Many thanks,
Jamie
_________________
Qwak - www.qwak.co.uk | Forum - www.qwak.co.uk/forum/

#15048 - DekuTree64 - Fri Jan 16, 2004 4:52 pm

Put them in an array. If you really want them to each have their own label, you can force the correct order in an ASM file by doing like
Code:
.data
.align 2
.global var1
var1:
.space 4
.global var2
var2:
.space 4

and so on, and they will stay that way. If you look at the ASM output from a C file with a global var declaration, they use something like comm var1, 4 instead, which means to declare a common symbol, that points to 4 bytes of space, and let the linker decide where to put it. .global is normally used for functions, but a symbol is a symbol so it works fine for both.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku

#15049 - Paul Shirley - Fri Jan 16, 2004 5:19 pm

removed

Last edited by Paul Shirley on Sun Mar 28, 2004 9:22 pm; edited 1 time in total

#15070 - poslundc - Fri Jan 16, 2004 8:53 pm

You can also use a struct to contain your related variables (which is a better idea than letting them roam free anyway).

Although I'm not sure if the compiler reserves the right to reorganize your struct if it thinks another method is more efficient, I've never had it do that to me (and I've used some wicked inefficient structs before).

EDIT: Crikey, I should've read Paul's post more carefully... my bad.

Dan.

#15072 - cosmic4z - Fri Jan 16, 2004 9:25 pm

OK, I put them in an array in the end ...

Thanks very much everyone for the information, very useful, thanks :)
_________________
Qwak - www.qwak.co.uk | Forum - www.qwak.co.uk/forum/