Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

208 lines
8.9KB

  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-2020 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 6.5, http://www.gnu.org/software/texinfo/ -->
  18. <head>
  19. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  20. <title>Constructing Calls (Using the GNU Compiler Collection (GCC))</title>
  21. <meta name="description" content="Constructing Calls (Using the GNU Compiler Collection (GCC))">
  22. <meta name="keywords" content="Constructing Calls (Using the GNU Compiler Collection (GCC))">
  23. <meta name="resource-type" content="document">
  24. <meta name="distribution" content="global">
  25. <meta name="Generator" content="makeinfo">
  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="C-Extensions.html#C-Extensions" rel="up" title="C Extensions">
  30. <link href="Typeof.html#Typeof" rel="next" title="Typeof">
  31. <link href="Nonlocal-Gotos.html#Nonlocal-Gotos" rel="prev" title="Nonlocal Gotos">
  32. <style type="text/css">
  33. <!--
  34. a.summary-letter {text-decoration: none}
  35. blockquote.indentedblock {margin-right: 0em}
  36. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  37. blockquote.smallquotation {font-size: smaller}
  38. div.display {margin-left: 3.2em}
  39. div.example {margin-left: 3.2em}
  40. div.lisp {margin-left: 3.2em}
  41. div.smalldisplay {margin-left: 3.2em}
  42. div.smallexample {margin-left: 3.2em}
  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.nolinebreak {white-space: nowrap}
  54. span.roman {font-family: initial; font-weight: normal}
  55. span.sansserif {font-family: sans-serif; font-weight: normal}
  56. ul.no-bullet {list-style: none}
  57. -->
  58. </style>
  59. </head>
  60. <body lang="en">
  61. <a name="Constructing-Calls"></a>
  62. <div class="header">
  63. <p>
  64. Next: <a href="Typeof.html#Typeof" accesskey="n" rel="next">Typeof</a>, Previous: <a href="Nonlocal-Gotos.html#Nonlocal-Gotos" accesskey="p" rel="prev">Nonlocal Gotos</a>, Up: <a href="C-Extensions.html#C-Extensions" accesskey="u" rel="up">C Extensions</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>
  65. </div>
  66. <hr>
  67. <a name="Constructing-Function-Calls"></a>
  68. <h3 class="section">6.6 Constructing Function Calls</h3>
  69. <a name="index-constructing-calls"></a>
  70. <a name="index-forwarding-calls"></a>
  71. <p>Using the built-in functions described below, you can record
  72. the arguments a function received, and call another function
  73. with the same arguments, without knowing the number or types
  74. of the arguments.
  75. </p>
  76. <p>You can also record the return value of that function call,
  77. and later return that value, without knowing what data type
  78. the function tried to return (as long as your caller expects
  79. that data type).
  80. </p>
  81. <p>However, these built-in functions may interact badly with some
  82. sophisticated features or other extensions of the language. It
  83. is, therefore, not recommended to use them outside very simple
  84. functions acting as mere forwarders for their arguments.
  85. </p>
  86. <dl>
  87. <dt><a name="index-_005f_005fbuiltin_005fapply_005fargs"></a>Built-in Function: <em>void *</em> <strong>__builtin_apply_args</strong> <em>()</em></dt>
  88. <dd><p>This built-in function returns a pointer to data
  89. describing how to perform a call with the same arguments as are passed
  90. to the current function.
  91. </p>
  92. <p>The function saves the arg pointer register, structure value address,
  93. and all registers that might be used to pass arguments to a function
  94. into a block of memory allocated on the stack. Then it returns the
  95. address of that block.
  96. </p></dd></dl>
  97. <dl>
  98. <dt><a name="index-_005f_005fbuiltin_005fapply"></a>Built-in Function: <em>void *</em> <strong>__builtin_apply</strong> <em>(void (*<var>function</var>)(), void *<var>arguments</var>, size_t <var>size</var>)</em></dt>
  99. <dd><p>This built-in function invokes <var>function</var>
  100. with a copy of the parameters described by <var>arguments</var>
  101. and <var>size</var>.
  102. </p>
  103. <p>The value of <var>arguments</var> should be the value returned by
  104. <code>__builtin_apply_args</code>. The argument <var>size</var> specifies the size
  105. of the stack argument data, in bytes.
  106. </p>
  107. <p>This function returns a pointer to data describing
  108. how to return whatever value is returned by <var>function</var>. The data
  109. is saved in a block of memory allocated on the stack.
  110. </p>
  111. <p>It is not always simple to compute the proper value for <var>size</var>. The
  112. value is used by <code>__builtin_apply</code> to compute the amount of data
  113. that should be pushed on the stack and copied from the incoming argument
  114. area.
  115. </p></dd></dl>
  116. <dl>
  117. <dt><a name="index-_005f_005fbuiltin_005freturn"></a>Built-in Function: <em>void</em> <strong>__builtin_return</strong> <em>(void *<var>result</var>)</em></dt>
  118. <dd><p>This built-in function returns the value described by <var>result</var> from
  119. the containing function. You should specify, for <var>result</var>, a value
  120. returned by <code>__builtin_apply</code>.
  121. </p></dd></dl>
  122. <dl>
  123. <dt><a name="index-_005f_005fbuiltin_005fva_005farg_005fpack"></a>Built-in Function: <em></em> <strong>__builtin_va_arg_pack</strong> <em>()</em></dt>
  124. <dd><p>This built-in function represents all anonymous arguments of an inline
  125. function. It can be used only in inline functions that are always
  126. inlined, never compiled as a separate function, such as those using
  127. <code>__attribute__ ((__always_inline__))</code> or
  128. <code>__attribute__ ((__gnu_inline__))</code> extern inline functions.
  129. It must be only passed as last argument to some other function
  130. with variable arguments. This is useful for writing small wrapper
  131. inlines for variable argument functions, when using preprocessor
  132. macros is undesirable. For example:
  133. </p><div class="smallexample">
  134. <pre class="smallexample">extern int myprintf (FILE *f, const char *format, ...);
  135. extern inline __attribute__ ((__gnu_inline__)) int
  136. myprintf (FILE *f, const char *format, ...)
  137. {
  138. int r = fprintf (f, &quot;myprintf: &quot;);
  139. if (r &lt; 0)
  140. return r;
  141. int s = fprintf (f, format, __builtin_va_arg_pack ());
  142. if (s &lt; 0)
  143. return s;
  144. return r + s;
  145. }
  146. </pre></div>
  147. </dd></dl>
  148. <dl>
  149. <dt><a name="index-_005f_005fbuiltin_005fva_005farg_005fpack_005flen"></a>Built-in Function: <em>size_t</em> <strong>__builtin_va_arg_pack_len</strong> <em>()</em></dt>
  150. <dd><p>This built-in function returns the number of anonymous arguments of
  151. an inline function. It can be used only in inline functions that
  152. are always inlined, never compiled as a separate function, such
  153. as those using <code>__attribute__ ((__always_inline__))</code> or
  154. <code>__attribute__ ((__gnu_inline__))</code> extern inline functions.
  155. For example following does link- or run-time checking of open
  156. arguments for optimized code:
  157. </p><div class="smallexample">
  158. <pre class="smallexample">#ifdef __OPTIMIZE__
  159. extern inline __attribute__((__gnu_inline__)) int
  160. myopen (const char *path, int oflag, ...)
  161. {
  162. if (__builtin_va_arg_pack_len () &gt; 1)
  163. warn_open_too_many_arguments ();
  164. if (__builtin_constant_p (oflag))
  165. {
  166. if ((oflag &amp; O_CREAT) != 0 &amp;&amp; __builtin_va_arg_pack_len () &lt; 1)
  167. {
  168. warn_open_missing_mode ();
  169. return __open_2 (path, oflag);
  170. }
  171. return open (path, oflag, __builtin_va_arg_pack ());
  172. }
  173. if (__builtin_va_arg_pack_len () &lt; 1)
  174. return __open_2 (path, oflag);
  175. return open (path, oflag, __builtin_va_arg_pack ());
  176. }
  177. #endif
  178. </pre></div>
  179. </dd></dl>
  180. <hr>
  181. <div class="header">
  182. <p>
  183. Next: <a href="Typeof.html#Typeof" accesskey="n" rel="next">Typeof</a>, Previous: <a href="Nonlocal-Gotos.html#Nonlocal-Gotos" accesskey="p" rel="prev">Nonlocal Gotos</a>, Up: <a href="C-Extensions.html#C-Extensions" accesskey="u" rel="up">C Extensions</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>
  184. </div>
  185. </body>
  186. </html>