Determining Endianness and Alignment (C Generator)
- Updated2023-02-21
- 2 minute(s) read
Use the C Code Generation Properties dialog box to specify Endianness and alignment for the C code generated by the LabVIEW C Generator.
Endianness describes how the CPU stores or loads a multiple-byte number in memory. CPUs can use big-endian or little-endian form. Some CPUs can switch between being big-endian or little-endian form. Refer to the CPU documentation to determine endianness for the CPU.
![]() |
Tip You can use the htonl function, which converts any value to big-endian form, in a C application to determine endianness. The following example demonstrates the htonl function. |
if ( htonl(2010) == 2010 ) printf("Big Endian\n");
else printf("Little Endian\n");
Alignment describes restrictions on where CPUs can store or load numbers in memory. The C Generator requires the most restrictive alignment among all the data types that LabVIEW uses. LVDefs_plat.h defines these data types. Alignment differs based on the compiler you are using and the compiler options you specify to compile the C code. Refer to the compiler and CPU documentation to determine the correct alignment value. Most compilers provide an __alignof macro to determine the alignment of a data type.
![]() |
Tip You can create a union of all data types you reference in LVDefs_plat.h to determine the most restrictive alignment. The following example demonstrates the union you might create. |
union max_align_t {
char t0;
short t1;
int t2;
long t3;
long long t4;
void* t5;
float t6;
double t7;
}
printf("Alignment = %ul\n", __alignof(union max_align_t));
