forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[solved]Struct alignment issue...?

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
Alberto



Joined: 12 Feb 2007
Posts: 63
Location: Sofia

PostPosted: Sun Mar 06, 2011 9:38 pm    Post subject: [solved]Struct alignment issue...? Reply with quote

Hi guys,

I am facing a strange (well, at least to me...) problem; I have the following struct-ures and defines:

Code:

#ifdef _USE_16_BIT_
    #define TColor u16
#else
    #define TColor u32
#endif

typedef struct TPopup
{
    TStringList* Items;
    TColor FNormFore;
    TColor FSelFore;
    ...
    TStringList* Images;
} TPopup;


NOTE: TStringList is a C++ class.

ok, it's not only like this, but it simplifies, and it's enough anyway.

Everything is fine when I build everything without defining _USE_16_BIT_.

When I define it, in a function (say SelectBook()) calling another function (say TPopup_Draw(TPopup* PU)) which receives as parameter a TPopup*,
just before the call to TPopup_Draw(PU), PU->Images is correct as I can inspect it within GDB; but just entering TPopup_Draw() it becomes corrupted. It's not NULL, but obviously its data make no sense as I can see again in GDB.

As I said, if I compile it without the _USE_16_BIT_ averything goes back to normality.

I fixed this issue by moving the second TStringList* (i.e. the Images one) right after the first, before the "TColor"s, but would like to understand why it behaves like this.

I also tried declaring the struct with the packed attribute, but receive an error by the linker, hence gave up...

Anybody can shed some light?

Cheers, A.


Last edited by Alberto on Wed Mar 09, 2011 6:22 am; edited 1 time in total
Back to top
View user's profile Send private message
Alberto



Joined: 12 Feb 2007
Posts: 63
Location: Sofia

PostPosted: Wed Mar 09, 2011 6:21 am    Post subject: Reply with quote

Nevermind...
I forgot to include a .h file where the #define for TColor u16 or u32 was :-|

The weird thing is, thou', that the compiler didn't show any errors (TColor in this case should have been unknown, shouldn't it??? Or no error would have raised, IMHO...)

Anyway, thanks to all who have read this so far ;-)
Back to top
View user's profile Send private message
Criptych



Joined: 12 Sep 2009
Posts: 87

PostPosted: Sun Mar 13, 2011 2:38 am    Post subject: Reply with quote

I've had similar problems before, and most times a simple "make rebuild" (if you include the SDK's build.mak) would solve the issue. Glad to hear you've solved it, though.
_________________
PSP-2001 // CFW 6.60 ME-1.2 and GCLite // Genesis Competition Entry
"So, we meet again: for the first time, for the last time." —Spaceballs
Back to top
View user's profile Send private message
Alberto



Joined: 12 Feb 2007
Posts: 63
Location: Sofia

PostPosted: Sun Mar 13, 2011 9:58 pm    Post subject: Reply with quote

Criptych wrote:
I've had similar problems before, and most times a simple "make rebuild" (if you include the SDK's build.mak) would solve the issue. Glad to hear you've solved it, though.


Well, I work with code::blocks, and _always_ do a rebuild; as I said it was a matter of a missing #include.
Weird, anyway, that I didn't get any unresolved type declaration for the TColor, which leads me to think the compiler _was_ aware of the type referred to by the #define of it, but got a different size, most probably u16 instead of u32; bah ;-)
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group