/* to get the definition of NULL */
#include <stdlib.h>

struct List {
  int head;
  struct List* tail;
};

typedef struct List list;

int length (list* l) {
  int i = 0;
  while (l != NULL) {
    i++;
    l = l->tail;
  }
  return i;
}

list* upto (int n) {
  list* l = NULL;
  while (n > 0) {
    list* k = (list*) malloc(sizeof(list));
    k->head = n;
    k->tail = l;
    l = k;
    n--;
  }
  return l;
}

int main() {
  list* l = upto(10);
  printf("%d\n", length(l));
}
