 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
ne0h
Joined: 21 Feb 2008 Posts: 386
|
Posted: Fri Dec 19, 2008 6:07 am Post subject: Bmp header struct, problem with word align... |
|
|
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 |
|
 |
ooPo Site Admin
Joined: 17 Jan 2004 Posts: 2032 Location: Canada
|
Posted: Fri Dec 19, 2008 6:16 am Post subject: |
|
|
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 |
|
 |
ne0h
Joined: 21 Feb 2008 Posts: 386
|
Posted: Fri Dec 19, 2008 6:23 am Post subject: |
|
|
....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 |
|
 |
|
|
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
|