# Data types
This chapter describes how C data types are represented on the
Hexagon processor.
## Basic data types
The following table lists the basic C data types and how they
are represented in hardware on the Hexagon processor.
**Basic data type representation**
| **C Type** | **Size (in bytes)** | **Hardware Representation** |
| --- | --- | --- |
| Char | 1 | Byte |
| Short | 2 | Halfword |
| Int | 4 | Word |
| Long | 4 | Word |
| Long long | 8 | Doubleword |
| Float | 4 | Word |
| Double | 8 | Doubleword |
| Long double | 8 | Doubleword |
| Enum | variable | variable |
| Pointer | 4 | Word |
By default, the char data type is unsigned. If a char variable must
be signed, declare the variable with the type signed char.
By default, enumeration types are assigned the smallest integer type
that can store the enumeration values. For example, an enum type
containing constants in the range 0–255 is stored in memory as a
single byte.
Note
The command option -fno-short-enums causes the C compilers
to allocate all enumeration types in 4 bytes.
## Memory alignment
The Hexagon processor requires data types to be properly aligned in
memory when they are accessed. An item of size N bytes is aligned
when its memory address mod N yields 0. For example, a 4-byte memory
access is aligned when the address is an integral multiple of 4.
**C data type alignment requirements**
| **Data type** | **Alignment requirement** |
| --- | --- |
| Scalar | Align to size of item ([Basic data types](https://docs.qualcomm.com/doc/80-N3040-23/topic/data-types.html#basic-data-types)). |
| Enumeration | Align according to underlying data type. |
| Array |
|
| Structure |
Align structure to alignment of structure member with
largest alignment.
Align members according to their data type.
If necessary, insert pad bytes between members.
If necessary, insert pad bytes after last member to make the
structure size an integral multiple of the alignment
requirement. (This ensures correct pointer arithmetic for
pointers to structures.)
Note
Members are allocated in memory in the order they
appear in a struct definition. |
| Packed structure |
Align structure to one-byte boundary.
Align members to one-byte boundaries.
Pad bytes not inserted between members.
>
>
> Note
>
>
> Members are guaranteed only to be one-byte aligned. |
| Bit field |
Same size and alignment rules as non-bit field structure
members.
Allocated from right to left (i.e., least to most
significant).
Must reside entirely within a storage unit appropriate for
their data type.
Unsigned by default. To create signed bit fields use the
signed type specifier.
|
| Union | Align to alignment of member with largest alignment. |
Data types are aligned only when they are accessed. Unaligned types
are allowed and must be handled properly by the compilers. Problems
arise only when dereferencing pointers are cast to data types with
stricter alignment requirements than the original type. For example:
int g(int *p){
return *p;
}
int f(void){
unsigned char a[4];
a[0] = 0xbeU;
a[1] = 0xbaU;
a[2] = 0xfeU;
a[3] = 0xcaU;
return g(a);
}
Copy to clipboard
In this example, array a is guaranteed only to be 1-byte aligned, but
function g() accesses a as an int, which (unless it is declared with
the packed attribute) must be 4-byte aligned. Thus the compiler will
generate a memw instruction in g().
**Alignment attributes**
Nonstandard memory alignment requirements must be explicitly
specified using the aligned attribute. For example:
int buffer[N] attribute ((aligned(8)));
Copy to clipboard
Note
You can specify any alignment value larger than the one
required.
The packed attribute can be used to declare that a data type must not
be aligned. packed and aligned can be used together to align a data
type to more than 1 byte but less than the type’s natural alignment.
For example:
int i attribute ((packed, aligned(2)));
Copy to clipboard
In this example, i is 2-byte aligned.
### Static allocation
Data types statically allocated in memory are subject to the
alignment requirements listed in [Memory alignment](https://docs.qualcomm.com/doc/80-N3040-23/topic/data-types.html#memory-alignment).
No additional requirements exist.
### Stack allocation
Data types allocated on the software stack [Software stack](https://docs.qualcomm.com/doc/80-N3040-23/topic/abi-software-stack.html#software-stack) are
subject to the alignment requirements listed in [Memory alignment](https://docs.qualcomm.com/doc/80-N3040-23/topic/data-types.html#memory-alignment).
Data allocated on the stack is only guaranteed to be up to 8-byte
aligned. To allocate stack data with more than 8-byte alignment, the
data address must be manually aligned. Follow these steps:
1. Declare a local char array with the following number of elements:
(size(data) + alignment(data) - 1)
Copy to clipboard
2. Cast the address of the array to an integer.
3. Clear the log:sub:2(alignment) low bits of the integer.
4. Cast the resulting value to a pointer to the type to be allocated.
Note
Currently, the compilers do not support stack realignment.
### Heap allocation
Data types allocated on the heap are subject to the alignment
requirements listed in [Memory alignment](https://docs.qualcomm.com/doc/80-N3040-23/topic/data-types.html#memory-alignment).
The standard allocator functions (malloc, realloc, calloc) return a
pointer that is aligned to the largest alignment required by any type
in the absence of the aligned attribute. For the Hexagon processor
this value is currently 8 bytes.
To allocate an object on the heap with alignment greater than 8
bytes, use the memalign function.
Note
memalign automatically performs the procedure described in
[Stack allocation](https://docs.qualcomm.com/doc/80-N3040-23/topic/data-types.html#stack-allocation).
Last Published: Oct 06, 2026
[Previous Topic
ABI overview](https://docs.qualcomm.com/bundle/publicresource/80-N3040-23/topics/abi-overview.md) [Next Topic
Software stack](https://docs.qualcomm.com/bundle/publicresource/80-N3040-23/topics/abi-software-stack.md)