Discussion Forum

overlaying struct pointers

Next Thread | Thread List | Previous Thread Start a Thread | Settings

DetailsMessage
Read-Only
Author
erik malund
Posted
11-Apr-2008 20:46 GMT
Toolset
C51
New! overlaying struct pointers

as many others, I'm sure, I am DATA space starved. We have, for backwards compatibility to process 'old files" (E1 format) which have the structures with the following pointers:

E1_SEIN  xdata *E1_SEINp;
E1_MAIN  xdata *GE1_MAINp;
E1_TXCH  xdata *GE1_TXCHp;

now when the data is loaded it is immediately recognized which format the data is in and if it is the new E2 format the above structures do not exist, but these do:

 E2_CHIF  xdata *GE2_CHIFp;
E2_DHDR  xdata *GE2_DHDRp;
E2_FTHD  xdata *GE2_FTHDp;

now, since the two formats are mutually exclusive, I could gain 6 DATA slots by overlaying them.
YES, I can do it with a union, but since these pointers are used all over the place this will be rather messy and I would like to use something like:

E1_SEIN  xdata *E1_SEINp;
E1_MAIN  xdata *GE1_MAINp;
E1_TXCH  xdata *GE1_TXCHp;
#define E2_CHIF  xdata *GE2_CHIFp *E1_SEINp
#define E2_DHDR  xdata *GE2_DHDRp *GE1_MAINp
#define E2_FTHD  xdata *GE2_FTHDp *GE1_TXCHp

which, of course do not work.

any 'elegant' way to do this. #define with typecasst"??.

Erik

Read-Only
Author
erik malund
Posted
11-Apr-2008 20:48 GMT
Toolset
C51
New! a note to the above

the code must be universal, no #if, #ifedef or such.

Erik

Read-Only
Author
Stephen Phillips
Posted
14-Apr-2008 16:31 GMT
Toolset
C51
New! RE: a note to the above
E1_SEIN  xdata *E1_SEINp;
E1_MAIN  xdata *GE1_MAINp;
E1_TXCH  xdata *GE1_TXCHp;
#define E2_CHIF  xdata *GE2_CHIFp *E1_SEINp
#define E2_DHDR  xdata *GE2_DHDRp *GE1_MAINp
#define E2_FTHD  xdata *GE2_FTHDp *GE1_TXCHp


You may wish to change this to

E1_SEIN  xdata *E1_SEINp;
E1_MAIN  xdata *GE1_MAINp;
E1_TXCH  xdata *GE1_TXCHp;
#define GE2_CHIFp  ((E2_CHIF xdata *) E1_SEINp)
#define GE2_DHDRp  ((E2_DHDR xdata *) GE1_MAINp)
#define GE2_FTHDp  ((E2_FTHD xdata *) GE1_TXCHp)


This makes the two sets of variables overlay with macro's doing the work.

Read-Only
Author
Hans-Bernhard Broeker
Posted
11-Apr-2008 21:03 GMT
Toolset
C51
New! RE: overlaying struct pointers

Define the unions, then use #defines to alias the individual members to look like ordinary variables.

Next Thread | Thread List | Previous Thread Start a Thread | Settings