I\'ve being using this code a while now, and it works fine, but it gave me some headache to implement it. It uses Flexible Array Member (FAM) aka Struct Hack. Now that C99 has t
The C
name for that construction is "flexible array member" (it might help your searches), or "struct hack" before C99.
Look at 6.7.2.1 in the Standard; there is example usage in the text.
You may also be interested in "Variable Length Arrays". See 6.7.5.2 in The Standard.
Actually, it's not variable-length arrays that you want to use here, but the struct
hack, aka "incomplete types", aka the "flexible array member":
typedef struct nO
{
int oper;
int nops;
struct nO *ptn[]; // <== look ma, no index!
} nodoOper;
// skip a bit
// no more (n-1) --------\
tam = sizeof(nodoOper) + n * sizeof(nodoOper *);
Only the last member of a struct
may be "flexible".
Variable-length arrays are a different feature:
void foo(int size)
{
float a[size]; // run-time stack allocation
printf("%lu\n", sizeof(a)); // and run-time sizeof (yuck)
}
(Oh, and these things are called arrays, not matrices.)