/* gcc -std=c11 */

#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>

typedef int T;

struct vector {
  size_t size;
  T data[];
};

struct vector *vector_alloc(size_t n, T initial_val) {
  struct vector *s;

  /* overflow */
  if (n > (SIZE_MAX - sizeof(struct vector)) / sizeof(T)) return NULL;

  s = malloc(sizeof(struct vector) + n * sizeof(T));
  /* malloc failed */
  if (!s) return NULL;

  for (size_t i = 0; i < n; ++i) s->data[i] = initial_val;
  return s;
}

void vector_free(struct vector *s) { free(s); }

int main(void) {
  size_t i, n = 10;
  struct vector *s = vector_alloc(n, 42);
  for (i = 0; i < n; ++i) printf("%zd\n", s->data[i]);
  vector_free(s);
  return 0;
}