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 

Bmp header struct, problem with word align...

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



Joined: 21 Feb 2008
Posts: 386

PostPosted: Fri Dec 19, 2008 6:07 am    Post subject: Bmp header struct, problem with word align... Reply with quote

Hi,
I'm writing a BMP library ( to load BMP files ),
but I'm getting some error with this:
Code:

typedef struct
{
    u16 magic_value; /** "BM" **/
    u32 file_size; /** the size of the BMP file in bytes **/
    u32 reserved; /** Reserved **/
    u32 rawdataoffset; /** Offset where bmp data can be found **/
} BmpHeader;

This is the BMP main header structure, and I've tried to load it with this:
Code:

[...]
BmpHeader Bmp_Header;
sceIoRead(fd, &Bmp_Header, sizeof(BmpHeader))
[...]

But when I try to print infos, I get a error because the 3th and the 4th bytes are "jumped", I know that this is probably because GCC what's to word align the structure, so I've tried to printf the size of the structure with sizeof() and I get 16bytes instead of 14...
So can I write a right struct?
I've tried with __attribute__((packed)), but I still get 16 bytes...
_________________
Get Xplora!
Back to top
View user's profile Send private message
ooPo
Site Admin


Joined: 17 Jan 2004
Posts: 2032
Location: Canada

PostPosted: Fri Dec 19, 2008 6:16 am    Post subject: Reply with quote

Make sure you're using the packed attribute in the right place. It can be tricky with a typedef:

Code:
typedef struct
{
(blahblah)
} __attribute__ ((packed)) BmpHeader;

Does that help?
Back to top
View user's profile Send private message Visit poster's website
ne0h



Joined: 21 Feb 2008
Posts: 386

PostPosted: Fri Dec 19, 2008 6:23 am    Post subject: Reply with quote

....mmm.
I've put the attrib in the same place ( if I put it after BmpHeader Gcc has said me that attribute are ignored ) but now works, instead of the last build... :(
Thanks ooPo! :)
_________________
Get Xplora!
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