Background: We're implementing a dynamic library in C++ that extends the functionality of a C program. For one of the main structs used in the C program, we would like to add our own library specific fields. Currently when we need a new field, we ask nicely that the developers of the C program add a field for us and we end up having a massive casting mess. I was wondering if we could instead do the following:
Header file of main program:
#ifdef __cplusplus
extern "C" {
#endif
/* ... */
typedef struct ImportantStruct {
/* Definitions */
} ImportantStruct
/* ... */
#ifdef __cplusplus
}
#endif
Our Header File:
//...
class ObjectType : public ImportantStruct {
// Our extra fields
}
//...
I guess I have two questions:
1) Is this even legal?
2) What problems does this create when the C program tries to use the struct part of the object?