Lesson plan

Flexible array member

C struct data types may end with a flexible array member with no specified size: typedef struct { size_t len; // there must be at least one other data member double arr[]; // the flexible array member must be last // The compiler may reserve extra padding space here, like it can between struct members } DoubleArray; Typically, such structures serve as the header in a larger, variable memory allocation: // see section on size and padding DoubleArray* darray = malloc(sizeof(DoubleArray) + ... * sizeof(double)); darray->len = ...; for (int i = 0; i len; i++) { darray->arr[i] = ...; // transparently uses the right type (double) }

Back to article

Article summary

C struct data types may end with a flexible array member with no specified size: typedef struct { size_t len; // there must be at least one other data member double arr[]; // the flexible array member must be last // The compiler may reserve extra padding space here, like it can between struct members } DoubleArray; Typically, such structures serve as the header in a larger, variable memory allocation: // see section on size and padding DoubleArray* darray = malloc(sizeof(DoubleArray) + ... * sizeof(double)); darray->len = ...; for (int i = 0; i len; i++) { darray->arr[i] = ...; // transparently uses the right type (double) }

Key claims

No claims recorded.

Discussion questions

  1. Summarise the article in your own words. Which single claim would you verify first, and why?
  2. Which claim in this article is most likely to be revised as the sources update? How would you check its current status?
  3. If two sources disagreed about one of these facts, what would you need in order to trust one over the other?

Bibliography

No sources recorded.

Key claims and bibliography are generated from the same tracked claims and sources as the article page.