gmacros: Add G_FLEXIBLE_STRUCT_SIZE
Submitted by Ilya Konstantinov
Link to original bug (#746941)
Description
Let's assume flexible struct Foo:
struct Foo { int bar; int flex[0]; };
or:
struct Foo { int bar; int flex[]; };
A common construct when allocating the struct is to use G_STRUCT_OFFSET:
int count = 1024; struct Foo* foo = g_malloc (G_STRUCT_OFFSET (struct Foo, flex[count]);
However, it obscures the real semantic meaning. I'd like to propose a new macro G_FLEXIBLE_STRUCT_SIZE (or G_FLEX_STRUCT_SIZE -- name is open to discussion too). It could be:
#define G_FLEXIBLE_STRUCT_SIZE G_STRUCT_OFFSET
though I'd rather prefer:
#define G_FLEXIBLE_STRUCT_SIZE(struct_type, flex_member, count) G_STRUCT_OFFSET(struct_type, flex_member[count])