‎05-13-2006 09:09 PM
‎05-15-2006 11:22 AM
‎05-15-2006 07:20 PM
‎05-16-2006 02:38 AM
‎05-16-2006 03:04 AM
Default structure alignment should reflect the _DEFALIGN macro that you can find under Build options >> Predefined macros menu item. In case you need to share data in binary format between programs written with different versione of CVI or from different compilers you may have a packing problem. For example, defalign macro defaults to 8 starting from cvi 6 on, but in the past I had some problems upgrading a program from cvi 5.5 (_DEFALIGN = 1) to newer versions of the compiler.
In this case you may need to use push and pop modifiers to define some structure with a different alignment than the default uset in the rest of your program. CVI online help describes this procedure; some examples of this usage can be found in several cvi standard include file (for example float.h).
‎05-16-2006 03:15 AM - edited ‎05-16-2006 03:15 AM
Actually the rule about packing is quite simple. A structure element will be packed on a multiple of the smaller value of the two that are:
@Little_Mole wrote:
Hi 🙂
- It took me some days to understand that my problem does relate to the structure packing behavior of compiler.
- Now I understand that I can solve my problem with #pragma pack.
- But since it took me a long time, so I want to get to understand the packing behavior a little bit more, may be someone can help explain it to me 🙂
my little code:
typedef struct {
unsigned char LittleCow1;
unsigned char LittleCow2;
} CowFamily;
- In this case, sizeof(CowFamily) will be 2, that is, 1 for each little cow, but if I change the code to
typedef struct {
unsigned char LittleCow;
unsigned int CowMom;
} CowFamily;
- sizeof(CowFamily) become 8, I understand that the compiler will start to pack the whole structure on to 4 bytes boundary if there is any 32-bit(or more) element inside the structure, correct? Is there any place where I can find more information regarding this behavior ?
- I meet this issue because I try to manage the structure using char *.
Thank you :)))
- Mole -
Message Edited by rolfk on 05-16-2006 10:18 AM