Skip navigation.
Home
The QNX Community Portal

View topic - Extending resource manager structures by inheritance

Extending resource manager structures by inheritance

anything that doesn't fit to other groups.

Extending resource manager structures by inheritance

Postby qnx630 » Fri Jan 31, 2014 9:22 am

Hi there

qnx.com

You must always place the iofunc structure that you’re overriding as the first
member of the new extended structure. This lets the common library work
properly in the default cases.


Generic example:

Code: Select all
/* 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;
};


My approach:

Code: Select all
/* 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;
};


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
qnx630
Active Member
 
Posts: 10
Joined: Mon Jun 24, 2013 11:11 am

Re: Extending resource manager structures by inheritance

Postby maschoen » Fri Jan 31, 2014 5:32 pm

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.
maschoen
QNX Master
 
Posts: 2640
Joined: Wed Jun 25, 2003 5:18 pm

Re: Extending resource manager structures by inheritance

Postby mario » Fri Jan 31, 2014 10:24 pm

Nice answer Mitchell.

More technical details here:

http://en.wikipedia.org/wiki/C%2B%2B11# ... n_old_data
mario
QNX Master
 
Posts: 4132
Joined: Sun Sep 01, 2002 1:04 am

Re: Extending resource manager structures by inheritance

Postby qnx630 » Mon Feb 03, 2014 6:32 am

Thank you both. It seems like my code is correct.
qnx630
Active Member
 
Posts: 10
Joined: Mon Jun 24, 2013 11:11 am


Return to General Programming

Who is online

Users browsing this forum: No registered users and 4 guests