How it works...

In this recipe, we modified the code from the Working with data alignment recipe by adding a packed attribute to each struct:

} __attribute__((packed));

This attribute instructs the compiler to not add padding bytes to the structs in order to conform to the alignment requirements of the target platform.

Running the preceding code gives us the following output:

If the compiler does not add padding bytes, the order of the data fields becomes insignificant. Given that the ObjectMetadata1 and ObjectMetadata2 structs have exactly the same data fields, their size in packed form becomes identical.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.69.143