Example 1 — Aliases for a struct and a function pointer
The code reads more cleanly without repeated struct and pointer syntax.
#include <stdio.h>
typedef struct { int x, y; } Point;
typedef int (*BinOp)(int, int);
static int add(int a, int b) { return a + b; }
int main(void) {
Point p = {3, 4};
BinOp op = add;
printf("Point (%d,%d)\n", p.x, p.y);
printf("result=%d\n", op(p.x, p.y));
return 0;
} How It Works
Pointreplacesstruct Pointeverywhere.BinOpnames the pointer-to-function type once.op(3, 4)callsaddthrough the alias.
