Skip to main content

Practice ยท 2 of 4

Transfer Hollows the Source

CHALLENGE
Difficulty: advanced+25 XP

Implement the buffer move that transfers ownership: ``c typedef struct { int *buf; size_t len; size_t cap; } vec_t; void vec_move(vec_t *dst, vec_t *src); void vec_free(vec_t *v); ` vec_move gives dst the buffer and *hollows* src (buf = NULL, len = cap = 0). vec_free releases what an owner holds. A file-scope int buffers_alive = 0;` increments in... nothing yet โ€” see the rules: define it yourself inside vec allocations if you need it; the tests only check the hollowing and value preservation.

Back to lesson: Practice: Ownership Contract Drills