Ok, so I know inheritance isn't actually implemented in C, but I've used one of the very common workarounds, and I'd like to know how to pass the "inherited" structure to a function (which is expecting an array of the base structure). The problem is, I have an array of the parent structure, and want to pass an equivalent array of the base structure (see below, I'm also getting a "suspicious pointer conversion warning"). Is this even possible, or do I have to create an interim function that will iterate through each base member of the parent structure and put it in a new array? (v. easy but inelegant). This is the best I've got so far:
Code:
typedef struct io {
int p_loc;
} io_t;
typedef struct led {
io_t io;
int state;
} led_t;
void io_set_locs(int loc[], io_t (*I)[]) {
int i=0;
for (; i<8; i++) I[i]->p_loc = loc[i];
}
void main(void) {
led_t L[8];
int loc_L[] = {0x110,0x120,0x140,0x180,0x040,0x080,0x104,0x108};
io_set_locs(loc_L, &L->io);
}