r6:Define:ALIGN

From liblfds.org
Jump to navigation Jump to search

Source File

/inc/liblfds.h

Prototype

#define ALIGN(alignment)  [compiler stack alignment directive]

Parameters

alignment

Alignment in bytes.

Return Value

No return value.

Notes

Atomic instructions require the variables they operate upon to meet certain memory alignment requirements. In liblfds, heap allocations for variables which will be used with the atomic instructions are aligned using abstraction_aligned_malloc, which provides access to the local aligned memory allocation function. However, in some places, variables which will be used with the atomic instructions are declared on the stack. To align these variables, compilers provide a keyword which permits the specification of alignment. This macro is the mechanism by which the compiler specific keyword for stack alignment is provided to liblfds.

Examples

On Windows, with the Microsoft C compiler, there exists the keyword __declspec. This keyword takes a number of arguments which indicate its particular function.

As such, the implementation of ALIGN on Windows with the Microsoft C compiler looks like this;

#define ALIGN(alignment)   __declspec( align(alignment) )

On Linux, with gcc, there exists the keyword __attribute__. This keyword takes a number of arguments which indicate its particular function.

As such, the implementation of ALIGN with gcc looks like this;

#define ALIGN(alignment)   __attribute__( aligned(alignment) )

See Also