Initially thought const members were preferable (immutable) but avoided them because in heap-allocated case, it's not as convenient as in C++, but I just remembered that with the C idiom with memcpy, it works just fine:
struct Point { const double x, y; };
struct Point *Point_new(const double x, const double y)
{
struct Point val = {.x=x, .y=y}, *ptr=malloc(sizeof(struct Point));
memcpy(ptr, &val, sizeof(struct Point));
return ptr;
}
It requires a little boilerplate which could be wrapped up in a va macro
Initially thought const members were preferable (immutable) but avoided them because in heap-allocated case, it's not as convenient as in C++, but I just remembered that with the C idiom with memcpy, it works just fine:
It requires a little boilerplate which could be wrapped up in a va macro