// see http://stackoverflow.com/q/30603685/228539

// Note that this does not address the issue of later on knowing
// how long the array actually is so you can iterate over it.

// Also note the concerns raised about memory safety in the above
// StackOverflow answers and comments.
	

#include <stdio.h>
#include <stdint.h>

typedef struct T_Function T_Function;
typedef T_Function * T_Inhibits[];

struct T_Function
{
	T_Inhibits * inhibitsTD; // pointer to array of pointers to this structure
    T_Function * (* inhibits)[]; // pointer to array of pointers to this structure
};

#define T_Function_Default(...) \
{ \
	.inhibitsTD = NULL, \
	__VA_ARGS__ \
}

typedef struct
{
	int i;
	float f;
} T_Simple;

T_Simple * s = & (T_Simple) {.i = 42, .f = 3.14};

typedef int T_Array4[4];
T_Array4 * pa4 = & (T_Array4) {1,2,3,4};

typedef int * T_Array4p[4];
int one, two, three, four;
T_Array4p * pa4p = & (T_Array4p) {&one,&two,&three,&four};
int * (* not_typed)[4] = & (int *[]) {&one,&two,&three,&four};

int main(void) {
	T_Function clutch = T_Function_Default();
	T_Function start = T_Function_Default();
	T_Function cruise = T_Function_Default();
	T_Function radio = T_Function_Default();

//  With an array variable to take the address of
    T_Function a, b, c;
    T_Function * ai[] = {&b, &c};
    a.inhibitsTD = &ai;
    b = a; // just to avoid unused errors

//  Taking the address of the compound literal
	T_Function x;
	// direct
	x.inhibitsTD = &(T_Function *[]) {&x};
	x.inhibits = &(T_Function *[]) {&x};
	// via typedef
	x.inhibitsTD = &(T_Inhibits) {&x};
	x.inhibits = &(T_Inhibits) {&x};
	
	clutch.inhibitsTD = &(T_Inhibits) {&start};
	start.inhibitsTD = &(T_Inhibits) {&radio, &cruise};
	
	start = clutch; // just to avoid unused errors
	clutch = start; // just to avoid unused errors
	
	return 0;
}
