1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
| struct myT{
char id[2];
long filesize;
// à noter la correction du type pour le champ reserved
//int reserved[2];
short reserved[2];
long headersize;
long infoSize;
long width;
long depth;
short biPlanes;
short bits;
long biCompression;
long biSizeImage;
long biXPelsPerMeter;
long biYPelsPerMeter;
long biClrUsed;
long biClrImportant;
} __attribute__((__packed__));
typedef myT BMPHEAD;
//===============================================================
// on ne peut pas simplifier les 2 définitions ci-dessus en
typedef struct {
...
} __attribute__((__packed__)) BMPHEAD;
// !!
//===============================================================
int main (int argc, char* argv [])
{
//printf("hello \n");
printf("size BMPHEAD = %I64u\n\n",sizeof (BMPHEAD));
printf("offset id = %I64u\n",offsetof (BMPHEAD,id));
printf("offset filesize = %I64u\n",offsetof (BMPHEAD,filesize));
printf("offset reserved = %I64u\n",offsetof (BMPHEAD,reserved));
printf("offset headersize = %I64u\n",offsetof (BMPHEAD,headersize));
printf("offset infoSize = %I64u\n",offsetof (BMPHEAD,infoSize));
printf("offset width = %I64u\n",offsetof (BMPHEAD,width));
printf("offset depth = %I64u\n",offsetof (BMPHEAD,depth));
printf("offset biPlanes = %I64u\n",offsetof (BMPHEAD,biPlanes));
printf("offset bits = %I64u\n",offsetof (BMPHEAD,bits));
printf("offset biCompression = %I64u\n",offsetof (BMPHEAD,biCompression));
printf("offset biSizeImage = %I64u\n",offsetof (BMPHEAD,biSizeImage));
printf("offset biSizeImage = %I64u\n",offsetof (BMPHEAD,biSizeImage));
printf("offset biXPelsPerMeter = %I64u\n",offsetof (BMPHEAD,biXPelsPerMeter));
printf("offset biYPelsPerMeter = %I64u\n",offsetof (BMPHEAD,biYPelsPerMeter));
printf("offset biClrUsed = %I64u\n",offsetof (BMPHEAD,biClrUsed));
printf("offset biClrImportant = %I64u\n",offsetof (BMPHEAD,biClrImportant));
return EXIT_SUCCESS;
}
==>
size BMPHEAD = 54
offset id = 0
offset filesize = 2
offset reserved = 6
offset headersize = 10
offset infoSize = 14
offset width = 18
offset depth = 22
offset biPlanes = 26
offset bits = 28
offset biCompression = 30
offset biSizeImage = 34
offset biSizeImage = 34
offset biXPelsPerMeter = 38
offset biYPelsPerMeter = 42
offset biClrUsed = 46
offset biClrImportant = 50
ce qui est le resultat attendu pour une structure compactée.
(si on ne compacte pas, on obtient :
size BMPHEAD = 56
offset id = 0
offset filesize = 4
offset reserved = 8
offset headersize = 12
offset infoSize = 16
offset width = 20
offset depth = 24
offset biPlanes = 28
offset bits = 30
offset biCompression = 32
offset biSizeImage = 36
offset biSizeImage = 36
offset biXPelsPerMeter = 40
offset biYPelsPerMeter = 44
offset biClrUsed = 48
offset biClrImportant = 52 |
Partager