National Instruments 320685D-01 Drums User Manual


 
Chapter 3 Windows 95/NT Compiler/Linker Issues
LabWindows/CVI Programmer Reference Manual 3-6
©
National Instruments Corporation
Structure Packing
The compilers differ in their default maximum alignment of elements within structures.
If your DLL API uses structures, you can guarantee compatibility among the different
compilers by using the
pack pragma to specify a specific maximum alignment factor. Place
this pragma in the DLL include file, before the definitions of the structures. You can choose
any alignment factor. After the structure definitions, reset the maximum alignment factor back
to the default, as in the following example:
#pragma pack (4) /* set maximum alignment to 4 */
typedef struct {
char a;
int b;
} MyStruct1;
typdef struct {
char a;
double b;
} MyStruct2;
#pragma pack () /* reset max alignment to default */
LabWindows/CVI predefines the __DEFALIGN macro to the default structure alignment of
the current compatible compiler.
Bit Fields
Borland C/C++ uses the smallest number of bytes necessary to hold the bit fields you specify
in a structure. The other compilers always use 4-byte elements. You can force compatibility
by adding a dummy bit field of the correct size to pad the set of contiguous bit fields so that
they fit exactly into a 4-byte element. Example:
typedef struct {
int a:1;
int b:1;
int c:1;
int dummy:29; /* pad to 32 bits */
} MyStruct;
00ProRef.book : 06chap03.fm Page 6 Monday, March 9, 1998 3:23 PM