Circular Buffer for UART RX

Medium C Memory
Solve this problem

Implement a circular buffer for UART receive data. The buffer must support push and pop operations and detect full/empty conditions.

Constraints

  • Buffer size is fixed at 16 bytes.
  • Use indices (not dynamic memory).
  • push returns 0 on success, -1 if full.
  • pop returns byte on success, -1 if empty.
  • Data type is uint8_t.
Starter codeC
1#include <stdint.h>2 3int buf_push(uint8_t data);4int buf_pop(uint8_t* out);