c++ - change bit size of packed struct in derived class -
the existing code:
typedef unsigned int uint; class { union xreg { uint allx; struct { uint x3 : 9; uint x2 : 9; uint x1 : 14; }__attribute__((__packed__)) __attribute__((aligned(4))); }; };
my requirement: now, need derive class a, , and in derived class, bit sizes of x1, x2 , x3 has change.
how do ? !
edit
i have class (lets a) approx. 7-8 unions (each representing hw register), , around 20 (approx.) functions. of these functions create instances of these unions, , use bits (x1, x2, x3 etc in example).
now, requirement add code new hardware has 95% of functionality same. changes include change in register bit sizes, , functionality change. so, among 20 functions, atleast 5 functions need change change implementation. reason me select inheritance , override these functions.
the rest 15 functions, change bit size changes. so, dont want override these functions, use base class ones. but, bit sizes of registers (unions) should change. how do that?
you cannot change bit-field length in derived class in c++.
what try, however, parametrize class bit_field lengths.
template <size_t n1, size_t n2, size_t n3 = 32 - n1 - n2> struct mystruct { uint bitfield1 : n1; uint bitfield2 : n2; uint bitfield3 : n3; };
now can instantiate struct n1, n2, n3 wish, example:
mystruct<9, 9> s;
Comments
Post a Comment