Structure_002dLayout-Pragmas.html 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Copyright (C) 1988-2017 Free Software Foundation, Inc.
  4. Permission is granted to copy, distribute and/or modify this document
  5. under the terms of the GNU Free Documentation License, Version 1.3 or
  6. any later version published by the Free Software Foundation; with the
  7. Invariant Sections being "Funding Free Software", the Front-Cover
  8. Texts being (a) (see below), and with the Back-Cover Texts being (b)
  9. (see below). A copy of the license is included in the section entitled
  10. "GNU Free Documentation License".
  11. (a) The FSF's Front-Cover Text is:
  12. A GNU Manual
  13. (b) The FSF's Back-Cover Text is:
  14. You have freedom to copy and modify this GNU Manual, like GNU
  15. software. Copies published by the Free Software Foundation raise
  16. funds for GNU development. -->
  17. <!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ -->
  18. <head>
  19. <title>Using the GNU Compiler Collection (GCC): Structure-Layout Pragmas</title>
  20. <meta name="description" content="Using the GNU Compiler Collection (GCC): Structure-Layout Pragmas">
  21. <meta name="keywords" content="Using the GNU Compiler Collection (GCC): Structure-Layout Pragmas">
  22. <meta name="resource-type" content="document">
  23. <meta name="distribution" content="global">
  24. <meta name="Generator" content="makeinfo">
  25. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  26. <link href="index.html#Top" rel="start" title="Top">
  27. <link href="Option-Index.html#Option-Index" rel="index" title="Option Index">
  28. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  29. <link href="Pragmas.html#Pragmas" rel="up" title="Pragmas">
  30. <link href="Weak-Pragmas.html#Weak-Pragmas" rel="next" title="Weak Pragmas">
  31. <link href="Symbol_002dRenaming-Pragmas.html#Symbol_002dRenaming-Pragmas" rel="prev" title="Symbol-Renaming Pragmas">
  32. <style type="text/css">
  33. <!--
  34. a.summary-letter {text-decoration: none}
  35. blockquote.smallquotation {font-size: smaller}
  36. div.display {margin-left: 3.2em}
  37. div.example {margin-left: 3.2em}
  38. div.indentedblock {margin-left: 3.2em}
  39. div.lisp {margin-left: 3.2em}
  40. div.smalldisplay {margin-left: 3.2em}
  41. div.smallexample {margin-left: 3.2em}
  42. div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
  43. div.smalllisp {margin-left: 3.2em}
  44. kbd {font-style:oblique}
  45. pre.display {font-family: inherit}
  46. pre.format {font-family: inherit}
  47. pre.menu-comment {font-family: serif}
  48. pre.menu-preformatted {font-family: serif}
  49. pre.smalldisplay {font-family: inherit; font-size: smaller}
  50. pre.smallexample {font-size: smaller}
  51. pre.smallformat {font-family: inherit; font-size: smaller}
  52. pre.smalllisp {font-size: smaller}
  53. span.nocodebreak {white-space:nowrap}
  54. span.nolinebreak {white-space:nowrap}
  55. span.roman {font-family:serif; font-weight:normal}
  56. span.sansserif {font-family:sans-serif; font-weight:normal}
  57. ul.no-bullet {list-style: none}
  58. -->
  59. </style>
  60. </head>
  61. <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  62. <a name="Structure_002dLayout-Pragmas"></a>
  63. <div class="header">
  64. <p>
  65. Next: <a href="Weak-Pragmas.html#Weak-Pragmas" accesskey="n" rel="next">Weak Pragmas</a>, Previous: <a href="Symbol_002dRenaming-Pragmas.html#Symbol_002dRenaming-Pragmas" accesskey="p" rel="prev">Symbol-Renaming Pragmas</a>, Up: <a href="Pragmas.html#Pragmas" accesskey="u" rel="up">Pragmas</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  66. </div>
  67. <hr>
  68. <a name="Structure_002dLayout-Pragmas-1"></a>
  69. <h4 class="subsection">6.62.10 Structure-Layout Pragmas</h4>
  70. <p>For compatibility with Microsoft Windows compilers, GCC supports a
  71. set of <code>#pragma</code> directives that change the maximum alignment of
  72. members of structures (other than zero-width bit-fields), unions, and
  73. classes subsequently defined. The <var>n</var> value below always is required
  74. to be a small power of two and specifies the new alignment in bytes.
  75. </p>
  76. <ol>
  77. <li> <code>#pragma pack(<var>n</var>)</code> simply sets the new alignment.
  78. </li><li> <code>#pragma pack()</code> sets the alignment to the one that was in
  79. effect when compilation started (see also command-line option
  80. <samp>-fpack-struct[=<var>n</var>]</samp> see <a href="Code-Gen-Options.html#Code-Gen-Options">Code Gen Options</a>).
  81. </li><li> <code>#pragma pack(push[,<var>n</var>])</code> pushes the current alignment
  82. setting on an internal stack and then optionally sets the new alignment.
  83. </li><li> <code>#pragma pack(pop)</code> restores the alignment setting to the one
  84. saved at the top of the internal stack (and removes that stack entry).
  85. Note that <code>#pragma pack([<var>n</var>])</code> does not influence this internal
  86. stack; thus it is possible to have <code>#pragma pack(push)</code> followed by
  87. multiple <code>#pragma pack(<var>n</var>)</code> instances and finalized by a single
  88. <code>#pragma pack(pop)</code>.
  89. </li></ol>
  90. <p>Some targets, e.g. x86 and PowerPC, support the <code>#pragma ms_struct</code>
  91. directive which lays out structures and unions subsequently defined as the
  92. documented <code>__attribute__ ((ms_struct))</code>.
  93. </p>
  94. <ol>
  95. <li> <code>#pragma ms_struct on</code> turns on the Microsoft layout.
  96. </li><li> <code>#pragma ms_struct off</code> turns off the Microsoft layout.
  97. </li><li> <code>#pragma ms_struct reset</code> goes back to the default layout.
  98. </li></ol>
  99. <p>Most targets also support the <code>#pragma scalar_storage_order</code> directive
  100. which lays out structures and unions subsequently defined as the documented
  101. <code>__attribute__ ((scalar_storage_order))</code>.
  102. </p>
  103. <ol>
  104. <li> <code>#pragma scalar_storage_order big-endian</code> sets the storage order
  105. of the scalar fields to big-endian.
  106. </li><li> <code>#pragma scalar_storage_order little-endian</code> sets the storage order
  107. of the scalar fields to little-endian.
  108. </li><li> <code>#pragma scalar_storage_order default</code> goes back to the endianness
  109. that was in effect when compilation started (see also command-line option
  110. <samp>-fsso-struct=<var>endianness</var></samp> see <a href="C-Dialect-Options.html#C-Dialect-Options">C Dialect Options</a>).
  111. </li></ol>
  112. <hr>
  113. <div class="header">
  114. <p>
  115. Next: <a href="Weak-Pragmas.html#Weak-Pragmas" accesskey="n" rel="next">Weak Pragmas</a>, Previous: <a href="Symbol_002dRenaming-Pragmas.html#Symbol_002dRenaming-Pragmas" accesskey="p" rel="prev">Symbol-Renaming Pragmas</a>, Up: <a href="Pragmas.html#Pragmas" accesskey="u" rel="up">Pragmas</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  116. </div>
  117. </body>
  118. </html>