3 ms·
The nesting can be taken care of: typedef struct list { int value; struct list *next; } list; #define cons(head, tail) ((list[]){{
by gsg 13y ago
The nesting can be taken care of:
typedef struct list {
int value;
struct list *next;
} list;
#define cons(head, tail) ((list[]){{.value = head, .next = tail}})
list *xs = cons(0, cons(1, cons(2, NULL)));
It isn't very useful though. Lifetime issues mean that such lists can't be mixed with dynamically allocated structure, returned from functions, etc.