#include /* line.c */ #include typedef struct { double x, y; } Point; typedef struct { Point from, to; } Line; double lineLength(const Line * l) { /* pass by reference cheaper than copying */ double dx = l->to.x - l->from.x; double dy = l->to.y - l->from.y; return sqrt( dx * dx + dy * dy ); } int main() { Line u = { {3.0, 4.0}, {7.0, 1.0} }; /* nested structure initialisation */ printf( "length = %f\n", lineLength( &u ) ); printf( "sizeof( Line ) = %d\n", sizeof( Line ) ); return 0; }