Forum Discussion
Altera_Forum
Honored Contributor
16 years agoYou are correct that the packing is different. The first short is not taking 2 bytes of space in the struct, it's taking 4. When the data is read back in, there is going to be garbage in every struct member after bfType because every read thereafter is off by 2 bytes.
I was able to use# pragma pack in my version of the Nios II tools. Does this code work for you?# include <stdio.h># pragma pack(2) typedef struct /**** BMP file header structure ****/ { unsigned short bfType; /* Magic number for file */ unsigned int bfSize; /* Size of file */ unsigned short bfReserved1; /* Reserved */ unsigned short bfReserved2; /* ... */ unsigned int bfOffBits; /* Offset to bitmap data */ } BITMAPFILEHEADER; int main() { printf("Hello from Nios II!\n"); printf("Size: %d\n", sizeof(BITMAPFILEHEADER)); return 0; } -edj