/* Examples of C99 compound literals and designated initializers. */ #include struct point { int x, y; }; static struct point point_at(int x, int y) { return (struct point){.x = x, .y = y}; } typedef struct point point; static point delta(point a, point b) { return (point) {.x = a.x - b.x, .y = a.y - b.y}; } static int distsq(point a, point b) { point d = delta(a, b); return d.x*d.x + d.y*d.y; } /* Untyped λ calculus */ typedef struct ulc { const char *var; struct ulc *rator, *rand, *body; } ulc; int main() { /* The S-combinator */ ulc s = { "x", .body = &(ulc) { "y", .body = &(ulc) { "z", .body = &(ulc) { .rator = &(ulc) { .rator = &(ulc) { "x" }, .rand = &(ulc) { "z" }}, .rand = &(ulc) { .rator = &(ulc) { "y" }, .rand = &(ulc) { "z" }}}}}}; printf("%d\n", distsq((point){2, -1}, (point){5, 3})); return 0; }