# Attributes Attributes are annotations that programmers add to the code. Attributes specify characteristics of program entities such as functions or variables. These characteristics influence the code generated by the compiler. Add an attribute by using the `__attribute__` keyword. For example: int add(int a, int b) __attribute__((always_inline)); Copy to clipboard For functions, add the attributes to the function declaration. **Commonly used attributes** aligned Copy to clipboard Specify the minimum alignment of a variable or function in bytes. In the following example, the code snippet aligns the variable to 32 bytes: > > > int var attribute ((aligned(32))); > Copy to clipboard always_inline Copy to clipboard Specify that the compiler must inline this function. noinline Copy to clipboard Specify that the compiler must not inline this function. optnone Copy to clipboard Change the optimization level for a function. If this attribute is added to a function, the compiler generates code for the function with the lowest optimization level. packed Copy to clipboard Specify that no padding is introduced between members of a structure. For example, in the following data structure: > > > struct __attribute__((packed)){ > char x; > int y; > } N; > Copy to clipboard No padding is introduced between elements `x` and `y` of struct `N`. Without the packed attribute, the compiler generates three bytes of padding between `x` and `y` to align `x` to its natural boundary. Note Dereferencing the address of a packed structure member might result in unaligned memory accesses. retain Copy to clipboard When attached to a function or variable definition, prevent section garbage collection in the linker. This attribute does not prevent other discard mechanisms, such as archive member selection and COMDAT group resolution. If the compiler does not emit the definition, this attribute has no effect (for example, because it was not used in the translation unit or the compiler was able to eliminate all of the uses). This attribute is typically combined with the used attribute to force the definition to be emitted and preserved into the final linked image. This attribute is only necessary on ELF targets; other targets prevent section garbage collection by the linker when using the used attribute alone. Using the attributes together should result in consistent behavior across targets. > > > __attribute__((retain)) int foo() { return 0; } > Copy to clipboard For more information about section garbage collection (`--gc-sections`), see the *Linker* chapter in the *Qualcomm Hexagon Utilities User Guide* (80-N2040-15). section Copy to clipboard Specify the section where a function or a variable is placed. In the following example, the code snippet places the `foo` function in the section named `.text2`: > > > int foo() attribute ((section(".text2"))); > Copy to clipboard used Copy to clipboard Mark a function or variable as used so the compiler does not delete it, even if it is not used anywhere in the application or if all uses are optimized out. This attribute is relevant for LTO, where the compiler can remove a larger number of symbols due to its global view of the code. In conjunction with the linker script KEEP directive, this attribute can be used to preserve variables that are not used anywhere in the source code, but that are required to be present in the final binary. Last Published: Oct 06, 2026 [Previous Topic Constraint modifiers](https://docs.qualcomm.com/bundle/publicresource/80-N3040-23/topics/inline-assembly-language.md) [Next Topic Libraries](https://docs.qualcomm.com/bundle/publicresource/80-N3040-23/topics/libraries.md)