#include <stdint.h>
#include <stdio.h>
#include <stddef.h>

struct threshold_t {
  uint8_t upper;
  uint8_t lower;
};

struct threshold_abc_t {
  struct threshold_t a;
  struct threshold_t b;
  struct threshold_t c;
};

static void print(const struct threshold_abc_t * const thresholds) {
  printf("{\"a\": {\"lower\": %u, \"upper\": %u},\n"
         " \"b\": {\"lower\": %u, \"upper\": %u},\n"
         " \"c\": {\"lower\": %u, \"upper\": %u}}\n",
    thresholds->a.lower, thresholds->a.upper,
    thresholds->b.lower, thresholds->b.upper,
    thresholds->c.lower, thresholds->c.upper);
}

static void set_thresholds_0(struct threshold_t * const threshold,
  const uint8_t lower, const uint8_t upper) {
  threshold->lower = lower;
  threshold->upper = upper;
}

enum threshold {
  THRESHOLD_A = offsetof(struct threshold_abc_t, a),
  THRESHOLD_B = offsetof(struct threshold_abc_t, b),
  THRESHOLD_C = offsetof(struct threshold_abc_t, c),
};

static void set_thresholds_1(struct threshold_abc_t * const thresholds,
  const enum threshold selection, const uint8_t lower, const uint8_t upper) {
  struct threshold_t * const threshold =
    (struct threshold_t * const)(&((uint8_t * const)thresholds)[selection]);
  threshold->lower = lower;
  threshold->upper = upper;
}

int main() {
  struct threshold_abc_t thresholds = {
    .a = {
      .lower = 5,
      .upper = 15,
    },
    .b = {
      .lower = 0,
      .upper = 20,
    },
    .c = {
      .lower = 0,
      .upper = 30,
    }
  };
  print(&thresholds);
  set_thresholds_0(&thresholds.a, 2, 50);
  print(&thresholds);
  set_thresholds_1(&thresholds, THRESHOLD_C, 69, 99);
  print(&thresholds);
  return 0;
}