Stage 1

Why Custom Data Types?

Raw integers and arrays can represent anything — but they tell you nothing about intent. Custom types add meaning, structure, and safety.

1.1 The grouping problem

before — scattered raw values
uint8_t  led_id     = 1;
bool     led_on     = false;
uint8_t  led_bright = 80;
uint32_t led_color  = 0xFF8C00;
/* Nothing stops you from accidentally passing
   led_color where led_id is expected. */
after — one named type
typedef struct {
    uint8_t  id;
    bool     on;
    uint8_t  brightness;
    uint32_t color;
} LedState;

LedState led = { .id=1, .on=false,
                  .brightness=80, .color=0xFF8C00 };

1.2 Enum: named states

sensor_state.c
typedef enum {
    SENSOR_IDLE,
    SENSOR_MEASURING,
    SENSOR_DATA_READY,
    SENSOR_ERROR
} SensorState;

SensorState state = SENSOR_IDLE;