Like so:
ImmutablePoint *make_immutable_point(int x, int y)
{
ImmutablePoint init = { .x = x, .y = y };
ImmutablePoint *p = malloc(sizeof *p);
if (p == NULL) abort();
memcpy(p, &init, sizeof *p);
return p;
}
(Note that unlike C++, there is no need to cast the return value of malloc
in C, and it is often considered bad form because it can hide other errors).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…