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 !?
Any suggestion would be appreciated.
--Source of "test.c"-------------------
#include <stdio.h>
typedef struct tagBMPHEAD {
char Signature[2];
unsigned int FileSize;
unsigned int Reserved;
unsigned int DataOffset;
} BMPHEAD;
typedef struct tagPixel24bit {
unsigned char Blue,Green,Red;
} PIXEL24;
void main(void)
{
BMPHEAD B;
PIXEL24 P;
int s;
printf("Size of variables in byte(s):\n");
printf("char = %d\n",sizeof(char));
printf("int = %d\n",sizeof(int));
s = 2*sizeof(char) + 3*sizeof(int);
printf("\nExpected size of BMPHEAD: %d\n",s);
printf(" Real size of BMPHEAD: %d\n",sizeof(B));
s = 3*sizeof(char);
printf("\nExpected size of PIXEL24: %d\n",s);
printf(" Real size of PIXEL24: %d\n",sizeof(P));
}
--- End of source ---------------------
--- Output of the program -------------
Size of variables in byte(s):
char = 1
int = 4
Expected size of BMPHEAD: 14
Real size of BMPHEAD: 16
Expected size of PIXEL24: 3
Real size of PIXEL24: 3
--- End of output ---------------------
With my best regards,
Laszlo Baranyai
--
SzIE Fizika-Automatika Tanszek
http://physics2.kee.hu/baranyai