We have a large C code base that has been developed over several decades. One of the features of the code is a large dependence on function pointers and pseudo inheritance. The idiom (as discussed here) follows like so:
typedef struct twod_ {
double x, y;
} twod;
typedef struct threed_ {
twod super;
double z;
} threed;
threed *point_3d;
twod *point_2d = (twod *)point3d;
At which point point_2d->x
and point_3d->x
are the same block of memory.
My questions are:
- Is this idiom still popular in modern production code? (Any recommended open source examples)
- This code has a requirement for performance -- does this idiom help with speed and/or memory usage?
- The way that it has been implemented (or due to many years of code bloat) it now feels a bit like spaghetti code -- generally speaking, is this a problem with the implementation, or the idiom? Or to put it another way, in an ideal world, would 500k LOC with this idiom be quickly understood?
Of course, the adage "if it aint broke, don't fix it" would be a good one to keep in mind; however, that isn't really helping us at the moment, so we think we might have to go deeper with refactoring...
Thanks!