Skip to content
UPEEC

Flexible Array Members

A struct whose last member is an array of unknown size, allocated together with the struct.

Intermediate
Comments 0
struct packet { uint16_t len; uint8_t data[]; };
struct packet *p = malloc(sizeof *p + n);

One allocation, contiguous memory — common in protocol code.

Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.

Discussion (0)

Sign in or join free to ask questions and discuss this topic.