Is there a standard for storing C ++ objects in memory? I want to set the char * pointer to a specific address in memory so that I can read the variables of some objects directly from the byte of memory by byte. When I use Dev C ++, the variables are stored one by one right in the memory address of the object in the order in which they were defined. Now, can it be different when using another compiler (for example, the variables are in a different order or somewhere else)? Thanks in advance.: -)
Variables cannot be in a different order as far as I know. However, there may be a different number of additions between members. I also think that all bets are disabled with virtual classes, and different implementations of user types (for example, std :: string) can be completely different between libraries (or even build options).
This seems to be a very suspicious thing. What do you need for: access to private members?
I believe that the layout of objects in memory is an implementation, not an order, a must, but an amount of space. In particular, you are likely to encounter problems with alignment of bytes and so on, especially on different platforms.
Can you give us some details of what you are trying to do?
, : P. , ++ , //.
, . , "#pragma pack" ... - , . , POD.
++ (public, protected ..). . :
struct A { int a; short b; char c; }; struct B { int a; public: short b; protected: char c; };
A a, b, c. B , . , , , "" .
, .
, , , . , , - .
/ , . gcc __attribute__((__packed__)) msvc #pragma pack.
__attribute__((__packed__))
#pragma pack
, , , , , - , , .
, , struct, , , , .
, , - , . (, , , )
, TCP/IP-. , , , , . , , , !
, ,
http://dieharddeveloper.blogspot.in/2013/07/c-memory-layout-and-process-image.html
. , . ELF . , , (PM) . , .
Source: https://habr.com/ru/post/1738549/More articles:Three-dimensional grid of regularly spaced points - pythonThreaded Erlang C- Node (cnode) Interaction howto? - erlangProblem creating index table - oracleChecking an empty object - c #IronPython Application Distribution - ironpythonAdding inheritance to an object developed by Qt - c ++XML: проверьте, существует ли что-либо между двумя узлами - xmlIs TFS effective for large teams and SVN for small teams? - performanceVS2010 RC: adding new domain service class class entities is empty - visual-studioRelease from ASP.Net Webforms Templates - oopAll Articles