Microsoft-Windows-Function-Attributes.html 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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): Microsoft Windows Function Attributes</title>
  20. <meta name="description" content="Using the GNU Compiler Collection (GCC): Microsoft Windows Function Attributes">
  21. <meta name="keywords" content="Using the GNU Compiler Collection (GCC): Microsoft Windows Function Attributes">
  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="Function-Attributes.html#Function-Attributes" rel="up" title="Function Attributes">
  30. <link href="MIPS-Function-Attributes.html#MIPS-Function-Attributes" rel="next" title="MIPS Function Attributes">
  31. <link href="MicroBlaze-Function-Attributes.html#MicroBlaze-Function-Attributes" rel="prev" title="MicroBlaze Function Attributes">
  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="Microsoft-Windows-Function-Attributes"></a>
  63. <div class="header">
  64. <p>
  65. Next: <a href="MIPS-Function-Attributes.html#MIPS-Function-Attributes" accesskey="n" rel="next">MIPS Function Attributes</a>, Previous: <a href="MicroBlaze-Function-Attributes.html#MicroBlaze-Function-Attributes" accesskey="p" rel="prev">MicroBlaze Function Attributes</a>, Up: <a href="Function-Attributes.html#Function-Attributes" accesskey="u" rel="up">Function Attributes</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="Microsoft-Windows-Function-Attributes-1"></a>
  69. <h4 class="subsection">6.31.17 Microsoft Windows Function Attributes</h4>
  70. <p>The following attributes are available on Microsoft Windows and Symbian OS
  71. targets.
  72. </p>
  73. <dl compact="compact">
  74. <dt><code>dllexport</code></dt>
  75. <dd><a name="index-dllexport-function-attribute"></a>
  76. <a name="index-_005f_005fdeclspec_0028dllexport_0029"></a>
  77. <p>On Microsoft Windows targets and Symbian OS targets the
  78. <code>dllexport</code> attribute causes the compiler to provide a global
  79. pointer to a pointer in a DLL, so that it can be referenced with the
  80. <code>dllimport</code> attribute. On Microsoft Windows targets, the pointer
  81. name is formed by combining <code>_imp__</code> and the function or variable
  82. name.
  83. </p>
  84. <p>You can use <code>__declspec(dllexport)</code> as a synonym for
  85. <code>__attribute__ ((dllexport))</code> for compatibility with other
  86. compilers.
  87. </p>
  88. <p>On systems that support the <code>visibility</code> attribute, this
  89. attribute also implies &ldquo;default&rdquo; visibility. It is an error to
  90. explicitly specify any other visibility.
  91. </p>
  92. <p>GCC&rsquo;s default behavior is to emit all inline functions with the
  93. <code>dllexport</code> attribute. Since this can cause object file-size bloat,
  94. you can use <samp>-fno-keep-inline-dllexport</samp>, which tells GCC to
  95. ignore the attribute for inlined functions unless the
  96. <samp>-fkeep-inline-functions</samp> flag is used instead.
  97. </p>
  98. <p>The attribute is ignored for undefined symbols.
  99. </p>
  100. <p>When applied to C++ classes, the attribute marks defined non-inlined
  101. member functions and static data members as exports. Static consts
  102. initialized in-class are not marked unless they are also defined
  103. out-of-class.
  104. </p>
  105. <p>For Microsoft Windows targets there are alternative methods for
  106. including the symbol in the DLL&rsquo;s export table such as using a
  107. <samp>.def</samp> file with an <code>EXPORTS</code> section or, with GNU ld, using
  108. the <samp>--export-all</samp> linker flag.
  109. </p>
  110. </dd>
  111. <dt><code>dllimport</code></dt>
  112. <dd><a name="index-dllimport-function-attribute"></a>
  113. <a name="index-_005f_005fdeclspec_0028dllimport_0029"></a>
  114. <p>On Microsoft Windows and Symbian OS targets, the <code>dllimport</code>
  115. attribute causes the compiler to reference a function or variable via
  116. a global pointer to a pointer that is set up by the DLL exporting the
  117. symbol. The attribute implies <code>extern</code>. On Microsoft Windows
  118. targets, the pointer name is formed by combining <code>_imp__</code> and the
  119. function or variable name.
  120. </p>
  121. <p>You can use <code>__declspec(dllimport)</code> as a synonym for
  122. <code>__attribute__ ((dllimport))</code> for compatibility with other
  123. compilers.
  124. </p>
  125. <p>On systems that support the <code>visibility</code> attribute, this
  126. attribute also implies &ldquo;default&rdquo; visibility. It is an error to
  127. explicitly specify any other visibility.
  128. </p>
  129. <p>Currently, the attribute is ignored for inlined functions. If the
  130. attribute is applied to a symbol <em>definition</em>, an error is reported.
  131. If a symbol previously declared <code>dllimport</code> is later defined, the
  132. attribute is ignored in subsequent references, and a warning is emitted.
  133. The attribute is also overridden by a subsequent declaration as
  134. <code>dllexport</code>.
  135. </p>
  136. <p>When applied to C++ classes, the attribute marks non-inlined
  137. member functions and static data members as imports. However, the
  138. attribute is ignored for virtual methods to allow creation of vtables
  139. using thunks.
  140. </p>
  141. <p>On the SH Symbian OS target the <code>dllimport</code> attribute also has
  142. another affect&mdash;it can cause the vtable and run-time type information
  143. for a class to be exported. This happens when the class has a
  144. dllimported constructor or a non-inline, non-pure virtual function
  145. and, for either of those two conditions, the class also has an inline
  146. constructor or destructor and has a key function that is defined in
  147. the current translation unit.
  148. </p>
  149. <p>For Microsoft Windows targets the use of the <code>dllimport</code>
  150. attribute on functions is not necessary, but provides a small
  151. performance benefit by eliminating a thunk in the DLL. The use of the
  152. <code>dllimport</code> attribute on imported variables can be avoided by passing the
  153. <samp>--enable-auto-import</samp> switch to the GNU linker. As with
  154. functions, using the attribute for a variable eliminates a thunk in
  155. the DLL.
  156. </p>
  157. <p>One drawback to using this attribute is that a pointer to a
  158. <em>variable</em> marked as <code>dllimport</code> cannot be used as a constant
  159. address. However, a pointer to a <em>function</em> with the
  160. <code>dllimport</code> attribute can be used as a constant initializer; in
  161. this case, the address of a stub function in the import lib is
  162. referenced. On Microsoft Windows targets, the attribute can be disabled
  163. for functions by setting the <samp>-mnop-fun-dllimport</samp> flag.
  164. </p></dd>
  165. </dl>
  166. <hr>
  167. <div class="header">
  168. <p>
  169. Next: <a href="MIPS-Function-Attributes.html#MIPS-Function-Attributes" accesskey="n" rel="next">MIPS Function Attributes</a>, Previous: <a href="MicroBlaze-Function-Attributes.html#MicroBlaze-Function-Attributes" accesskey="p" rel="prev">MicroBlaze Function Attributes</a>, Up: <a href="Function-Attributes.html#Function-Attributes" accesskey="u" rel="up">Function Attributes</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>
  170. </div>
  171. </body>
  172. </html>