memory - Is there a standard-compliant way to specify field offsets in C++? -


I have a part of the virtual memory by external code I am trying to reverse the engineer. I do not know the whole structure of this memory, but I know some areas (e.g., the part starts with Int 32 called "FU" and is a double called Offset 0x C 'Double'). I want to define a structure and inevitably describe it - putting an indicator for the piece of memory in that structure, and it will have to be raised up, I am not sure that another traditional name for this technique Yes, but I'll refer it as an 'overlay type'. Here is a sketch I want to do: START_OVERLAY_TYPE (my_type, 0xFF) // struct my_type name, size 0xFF FIELD (0x00, int32_t foo); // area int2_t fx 0x00 field (0x0 c, double bar); // field double bar 0x0C at END_OVERLAY_TYPE

Do not use macros to have one plus, but I do not see a good way around them.

Current implementation with me, I extend it (something like):

  __ pragma (pack (push, 1)) template & lt; size_t p & gt; struct padding_t {unsigned four pads [p]; }; & Lt; & gt; struct padding_t & lt; 0 & gt; {}; Struct my_type {union} {struct: padding_t & lt; 0xFF & gt; {}; // Make sure the total size is 0xFF strait: padding_t & lt; 0x00 & gt; {Int32_t foo; }; 0 field 0x00 structure: padding_t & lt; 0x0c & gt; {Double bar; }; // field 0x0C}; }; __Report (Pack):   

At least in the editions, I try Clag, GCC, and VC ++ (with practical changes). Unfortunately, alerts are abundant due to non-standard use of unknown structures.

Is there any way to get the same effect in the standard? Requirements are that it is quite simple to declare (like current macro), and for consumers, the use

  struct is different from my_type {int32_t foo}. Double bar; }   

for at least accidental supervisor.

The current code will work for my purposes, I'm just curious if there is a better perspective that I am ignoring.

In this way you can try to do something with the built-in conversion and assignment operator with the built-in value internally. In this way, instead of using unknown structures, the name is named, but the internal operator becomes anonymous part through overloading.

I tried this with some client code (passing through function, receiving value / setting) and everything seemed fine, it is definitely possible that I lost a scenario somewhere.

  __ pragma (pack (push, 1)) template & lt; Size_t p, typename t & gt; struct padding_t {unsigned four pads [p]; T wall; Operator T () Concern {return value;} operator T & A. () {Return val;} padding_t & lt; p, t & gt; Operator = (Const T & RA) {val = rhs; Return * This;}}; Template & lt; Typename t & gt; Struct padding_t & lt; 0, t & gt; {TWAL; Operator T () Concern {return value;} operator T & A. () {Return val;} padding_t & lt; 0, t & gt; Operator = (Const T & RA) {val = rhs; Return * This;}}; Template & lt; size_t p & gt; struct sizing_t {unsigned four pads [p]; }; Struct my_type {union {sizing_t & lt; 0xFF & gt; Size; // Ensure that the total size 0xFF padding_t & lt; 0x00, int32_t & gt; Foo; // field 0x00 padding_t & lt; 0x0C, double & gt; Bar; // field 0x0C}; }; __Pack (Pack (pop))    

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -