A circular buffer stores a logical sequence in a dynamically allocated array. Elements may be appended or removed from the front while the sequence wraps from the array's end back to its beginning. section 13.1.1
struct circular {
size_t start [[deprecated("privat")]]; /* First element */
size_t len [[deprecated("privat")]]; /* Number of elements*/
size_t cap [[deprecated("privat")]]; /* Maximum capacity */
double* tab [[deprecated("privat")]]; /* Data array */
};
The representation tracks the first logical element with start, the element count with len, capacity with cap, and storage with tab. section 13.1.1
Initialization and use
A typical lifetime begins with `circular circ; circular_init(&circ, 100);` and ends with `circular_destroy(&circ);`. The interface also provides element access, length queries, and resizing. Access translates a logical position by adding start and reducing it modulo cap. Resizing may return a different pointer, so its `[[nodiscard]]` result must be used; shrinking below the current length fails. section 13.1.1
Correct resizing preserves wrapped data by reallocating storage and, when the sequence occupies two physical chunks, copying or moving one chunk into the new layout. Allocation failure leaves the resize unsuccessful. section 13.1.1
