Determination of valid alignment values for C/C + + structures

Source: Internet
Author: User

See such a written question, as follows

The following structure is defined on a 32-bit machine:
struct xx{    longlong  _x1;     Char _x2;     int _x3;     Char _x4[2];     Static int _x5;}; int xx::_x5;

The correct answer is 24.

Did you do the right thing? The following explanations are given:

Determine the effective alignment value of the struct:

  1. When not explicitly specified, the length of the longest member in the struct is its valid value
  2. When specified with #pragma pack (n), its value is the lesser of the length of the longest member in N and struct.
  3. When specifying a length with __attribute__ ((__packed__)), force a valid alignment value for the struct by this value

Conv New, published in the blog Park

Reprint please indicate the source, welcome mail exchange:[email protected]

Determination of valid alignment values for C/C + + structures

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.