API
API
C
API reference (Align) — Alpha (1.14.2)

Defold Learn logo


Align

Alignment macros. Use for compiler compatibility

Include: #include <dmsdk/dlib/align.h>
MACROS
DM_ALIGN (x, a) value alignment macro
DM_ALIGN64 (x, a) 64-bit value alignment macro
DM_ALIGNED (a) data structure alignment macro

Macros

DM_ALIGN

Align a value to a boundary

x value to align
a alignment boundary

EXAMPLES

Align 24 to 16 alignment boundary. results is 32:
int result = DM_ALIGN(24, 16);

DM_ALIGN64

Round a nonnegative integer value up to an alignment boundary using 64-bit unsigned arithmetic, including on 32-bit targets. The result is a uint64_t. Use DM_ALIGN for pointer alignment. The alignment must be a nonzero power of two, and the rounded value must fit in uint64_t. Overflow is not checked. Arguments must not have side effects.

x nonnegative integer value to align
a nonzero power-of-two alignment boundary

EXAMPLES

Round up across the 32-bit size boundary without truncating the result:
uint64_t result = DM_ALIGN64(UINT32_MAX, 16); // 4294967296

DM_ALIGNED

Data structure alignment

a number of bytes to align to

EXAMPLES

Align m_Data to 16 bytes alignment boundary:
int DM_ALIGNED(16) m_Data;