In C #, you have good alignment attributes, such as:
[StructLayout(LayoutKind.Explicit)] public struct Message { [FieldOffset(0)] public int a; [FieldOffset(4)] public short b; [FieldOffset(6)] public int c; [FieldOffset(22)] //Leave some empty space just for the heck of it. public DateTime dt; }
Which gives you great control over how you need your structure laid out in memory. Is there such a thing in standard C ++?
Compilers usually support this with #pragma, but this is not something that is included in the C ++ standard and therefore not portable.
For an example with the Microsoft compiler, see: http://msdn.microsoft.com/en-us/library/2e70t5y1(VS.80).aspx
Hmya, : #, , . [FieldOffset] .
, :
#pragma pack(push, 1) public struct Message { int a; short b; int c; char padding1[12]; long long dt; } #pragma pack(pop)
"#pragma pack". Microsoft http://msdn.microsoft.com/en-us/library/2e70t5y1%28VS.80%29.aspx GCC google - .
#, , C ( C) " ".
Source: https://habr.com/ru/post/1748232/More articles:Why does setting a property allow the property to crash the application? - c #Rails: создание подкаталогов в модели? - ruby-on-rails.NET An Effective Way to Create a WORD Doc - Server Side - .netLightweight MVC - no frames - phpSolve a brute force exercise - mathFileSystemWatcher supports parent directory - .netHow to get the second word from a string? - javaDjango: Is there a way to have a "date range unique"? - pythonBundler support http auth - ruby | fooobar.comFancybox: Get id of anchor element / element - javascriptAll Articles