No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

162 líneas
7.1KB

  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>Local Labels (Using the GNU Compiler Collection (GCC))</title>
  21. <meta name="description" content="Local Labels (Using the GNU Compiler Collection (GCC))">
  22. <meta name="keywords" content="Local Labels (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="Labels-as-Values.html#Labels-as-Values" rel="next" title="Labels as Values">
  31. <link href="Statement-Exprs.html#Statement-Exprs" rel="prev" title="Statement Exprs">
  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="Local-Labels"></a>
  62. <div class="header">
  63. <p>
  64. Next: <a href="Labels-as-Values.html#Labels-as-Values" accesskey="n" rel="next">Labels as Values</a>, Previous: <a href="Statement-Exprs.html#Statement-Exprs" accesskey="p" rel="prev">Statement Exprs</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="Locally-Declared-Labels"></a>
  68. <h3 class="section">6.2 Locally Declared Labels</h3>
  69. <a name="index-local-labels"></a>
  70. <a name="index-macros_002c-local-labels"></a>
  71. <p>GCC allows you to declare <em>local labels</em> in any nested block
  72. scope. A local label is just like an ordinary label, but you can
  73. only reference it (with a <code>goto</code> statement, or by taking its
  74. address) within the block in which it is declared.
  75. </p>
  76. <p>A local label declaration looks like this:
  77. </p>
  78. <div class="smallexample">
  79. <pre class="smallexample">__label__ <var>label</var>;
  80. </pre></div>
  81. <p>or
  82. </p>
  83. <div class="smallexample">
  84. <pre class="smallexample">__label__ <var>label1</var>, <var>label2</var>, /* <span class="roman">&hellip;</span> */;
  85. </pre></div>
  86. <p>Local label declarations must come at the beginning of the block,
  87. before any ordinary declarations or statements.
  88. </p>
  89. <p>The label declaration defines the label <em>name</em>, but does not define
  90. the label itself. You must do this in the usual way, with
  91. <code><var>label</var>:</code>, within the statements of the statement expression.
  92. </p>
  93. <p>The local label feature is useful for complex macros. If a macro
  94. contains nested loops, a <code>goto</code> can be useful for breaking out of
  95. them. However, an ordinary label whose scope is the whole function
  96. cannot be used: if the macro can be expanded several times in one
  97. function, the label is multiply defined in that function. A
  98. local label avoids this problem. For example:
  99. </p>
  100. <div class="smallexample">
  101. <pre class="smallexample">#define SEARCH(value, array, target) \
  102. do { \
  103. __label__ found; \
  104. typeof (target) _SEARCH_target = (target); \
  105. typeof (*(array)) *_SEARCH_array = (array); \
  106. int i, j; \
  107. int value; \
  108. for (i = 0; i &lt; max; i++) \
  109. for (j = 0; j &lt; max; j++) \
  110. if (_SEARCH_array[i][j] == _SEARCH_target) \
  111. { (value) = i; goto found; } \
  112. (value) = -1; \
  113. found:; \
  114. } while (0)
  115. </pre></div>
  116. <p>This could also be written using a statement expression:
  117. </p>
  118. <div class="smallexample">
  119. <pre class="smallexample">#define SEARCH(array, target) \
  120. ({ \
  121. __label__ found; \
  122. typeof (target) _SEARCH_target = (target); \
  123. typeof (*(array)) *_SEARCH_array = (array); \
  124. int i, j; \
  125. int value; \
  126. for (i = 0; i &lt; max; i++) \
  127. for (j = 0; j &lt; max; j++) \
  128. if (_SEARCH_array[i][j] == _SEARCH_target) \
  129. { value = i; goto found; } \
  130. value = -1; \
  131. found: \
  132. value; \
  133. })
  134. </pre></div>
  135. <p>Local label declarations also make the labels they declare visible to
  136. nested functions, if there are any. See <a href="Nested-Functions.html#Nested-Functions">Nested Functions</a>, for details.
  137. </p>
  138. <hr>
  139. <div class="header">
  140. <p>
  141. Next: <a href="Labels-as-Values.html#Labels-as-Values" accesskey="n" rel="next">Labels as Values</a>, Previous: <a href="Statement-Exprs.html#Statement-Exprs" accesskey="p" rel="prev">Statement Exprs</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>
  142. </div>
  143. </body>
  144. </html>