Can someone explain maybe with simple examples about how structs and more importantly nesting a union in a struct works?
right now i have something like~
the basic premise is it's a "calculator" of sorts... I'm using the struct to define various evaluations methods i have like addition/subtraction etc... The union comes in because the calculator needs to be versatile and should be able to work with any new functions i put in later. Being able to work with zeroary, unary, and binary operators simultaenously without needing to add new code...Code:typedef struct Operator { char symbol; int operands; union { void *f; double (*f0)(void); double (*f1) (double x); double (*f2) (double x, double y); } }Operator;
I'm confused about the union completely I'm not really sure how it works. Structs I know a little about.