Extending resource manager structures by inheritance

Hi there

qnx.com

Generic example:

[code]/* Define our overrides before including <sys/iofunc.h> */
struct device;
#define IOFUNC_ATTR_T
#include <sys/iofunc.h>
#include <sys/dispatch.h>

struct device {
iofunc_attr_t attr;
int my_new_member;
};
[/code]

My approach:

[code]/* Define our overrides before including <sys/iofunc.h> */
struct device;
#define IOFUNC_ATTR_T
#include <sys/iofunc.h>
#include <sys/dispatch.h>

struct device: public iofunc_attr_t {
int my_new_member;
};
[/code]

How safe to extend structures in such a way? I suppose that size and order of members of new structure should stay the same (of course I will not use multiple and virtual inheritance).

Thanks

I’m going to answer this, without really answering this.

You seem to be asking whether a certain C++ construct will extend a memory area in a specific way.
How safe this is depends on how well you understand what the C++ compiler is required to do.
If you understand exactly what it will do, then you know already whether this will work or not.
If you don’t understand, then I would say it’s not very safe.

I use the word “required” above, because it’s not important what it actually does.
If it does something, like put the new element after the existing elements, it will work now, but if it’s not required to, then in the future your code may unexpectedly stop working.

Nice answer Mitchell.

More technical details here:

en.wikipedia.org/wiki/C%2B%2B11# … n_old_data

Thank you both. It seems like my code is correct.