Baranyai L�szl� <[EMAIL PROTECTED]> wrote:
> Dear Expert Users!
>
> My name is Laszlo Baranyai and this is the first time I have written to this
> list. I am working with digital image processing and would like to compile
> my algorithms under Linux as well. The following program is written in C
> and has strange result: the 14 byte structure allocates 16 bytes, the 3 byte
> structure requires 3 bytes !?
Interesting. Is this x86 linux or sparc linux? What compiler?
Ok, now to the answer:
>
> --Source of "test.c"-------------------
> #include <stdio.h>
>
> typedef struct tagBMPHEAD {
> char Signature[2];
> unsigned int FileSize;
> unsigned int Reserved;
> unsigned int DataOffset;
> } BMPHEAD;
the above structure has 2 chars followed by 3 ints.
If you don't tell the compiler to pack your structures, then
it is padding them so that ints land on a boundary which
makes accessing them faster (on Suns, it makes it MUCH
faster, since Suns will bus error if you try to get
something longer than a byte from a non-aligned address).
I've not needed to pack my structures in a while, so I've
forgotten the compiler option to do that. check the man page...
>
> typedef struct tagPixel24bit {
> unsigned char Blue,Green,Red;
> } PIXEL24;
this structure does not have any elements which 'need'
alignment at something other than a byte boundary, so
packing is done regardless.
A warning - some compilers may force the STRUCTURE to be
aligned even if there are only chars inside it!
rc
Rusty Carruth Email: [EMAIL PROTECTED] or [EMAIL PROTECTED]
Voice: (480) 345-3621 SnailMail: Schlumberger ATE
FAX: (480) 345-8793 7855 S. River Parkway, Suite 116
Ham: N7IKQ @ 146.82+,pl 162.2 Tempe, AZ 85284-1825
ICBM: 33 20' 44"N 111 53' 47"W