What is Types?
Types module defines fixed-width integer types for safety-critical systems. All framework code uses uint32_t, int16_t, etc. instead of bare int or long. This ensures consistent behavior across platforms (8-bit MCU, 32-bit ARM, 64-bit x86).
Key principle: Platform-independent sizing guarantees.
Available Types
uint8_t uint16_t uint32_t uint64_t
int8_t int16_t int32_t int64_t
bool (C11 standard, true/false)
size_t (pointer-sized)
Quick Start
1. Include Header
#include "rte/types/rte_types.h"
2. Use Fixed-Width Types
int counter;
unsigned long value;
uint32_t counter;
uint64_t value;
Type Ranges
uint8_t: 0 to 255
uint16_t: 0 to 65,535
uint32_t: 0 to 4,294,967,295
uint64_t: 0 to (2^64 - 1)
int8_t: -128 to 127
int16_t: -32,768 to 32,767
int32_t: -2,147,483,648 to 2,147,483,647
int64_t: -(2^63) to +(2^63 - 1)
Practical Examples
Example 1: Type-Safe Structure
typedef struct {
uint32_t message_id;
uint16_t length;
int16_t temperature;
uint8_t flags;
} train_msg_t;
STATIC_ASSERT(sizeof(train_msg_t) == 9);
Example 2: Sized Counters
uint16_t packet_count;
uint32_t byte_count;
uint64_t total_uptime_ms;
Best Practices
- Never use bare int, long, char
- Always explicit type: int32_t, uint8_t, etc.
- Makes size guarantees visible
- Match type to purpose
- 16-bit counters: values 0-65535?
- 32-bit time: milliseconds for ~49 days?
- Don't over-allocate
- Use uint8_t for bytes
- Not unsigned char (confusing)
- Not int (wrong size)
- Always uint8_t for byte arrays
- Use bool for single flags
- bool enabled = true;
- For multiple flags: uint32_t flags; with bit manipulation
- Watch for overflow
- uint8_t max = 255; max++; // Wraps to 0
- int32_t sum = MAX + 1; // Undefined behavior!
- Use next size up if needed
See Also