I just want a recursive data unions for boolean expressions, without using strings. Maybe this example will be more clear (this is not boolean expressions but it's simpler).
I have three structs:
Code:
typedef struct {
int length;
int x;
int y;
} square;
typedef struct {
int width;
int height;
int x;
int y;
} rectangle;
typedef struct {
? shape_left;
? shape_right;
} overlay;
The last struct has ? marks because those could be a square or rectangle.
Here is some sample data:
Code:
square sq = { 5, 10, 20 };
rectangle rt = { 4, 15, 10, 20 };
overlay ov1 = {sq, rt };
overlay ov2 = {rt, sq};
Is that more clear perhaps?
If you know Java, this would be represented as:
Code:
interface shape { }
class square implements shape {
.... data here
}
class rectangle implements shape {
.... data here
}
class overlay implements shape {
shape left;
shape right;
overlay(shape left, shape right) {
....
}
}
I know C isn't object oriented, but I'm not trying to use objects here. I'm just trying to have data of a type that I cannot declare at compilation time and has to be flexible.