Arrays.html 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Copyright (C) 1992-2019 Free Software Foundation, Inc.
  4. Contributed by Cygnus Support. Written by Julia Menapace, Jim Kingdon,
  5. and David MacKenzie.
  6. Permission is granted to copy, distribute and/or modify this document
  7. under the terms of the GNU Free Documentation License, Version 1.3 or
  8. any later version published by the Free Software Foundation; with no
  9. Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
  10. Texts. A copy of the license is included in the section entitled "GNU
  11. Free Documentation License". -->
  12. <!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ -->
  13. <head>
  14. <title>STABS: Arrays</title>
  15. <meta name="description" content="STABS: Arrays">
  16. <meta name="keywords" content="STABS: Arrays">
  17. <meta name="resource-type" content="document">
  18. <meta name="distribution" content="global">
  19. <meta name="Generator" content="makeinfo">
  20. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  21. <link href="index.html#Top" rel="start" title="Top">
  22. <link href="Symbol-Types-Index.html#Symbol-Types-Index" rel="index" title="Symbol Types Index">
  23. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  24. <link href="Types.html#Types" rel="up" title="Types">
  25. <link href="Strings.html#Strings" rel="next" title="Strings">
  26. <link href="Subranges.html#Subranges" rel="prev" title="Subranges">
  27. <style type="text/css">
  28. <!--
  29. a.summary-letter {text-decoration: none}
  30. blockquote.smallquotation {font-size: smaller}
  31. div.display {margin-left: 3.2em}
  32. div.example {margin-left: 3.2em}
  33. div.indentedblock {margin-left: 3.2em}
  34. div.lisp {margin-left: 3.2em}
  35. div.smalldisplay {margin-left: 3.2em}
  36. div.smallexample {margin-left: 3.2em}
  37. div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
  38. div.smalllisp {margin-left: 3.2em}
  39. kbd {font-style:oblique}
  40. pre.display {font-family: inherit}
  41. pre.format {font-family: inherit}
  42. pre.menu-comment {font-family: serif}
  43. pre.menu-preformatted {font-family: serif}
  44. pre.smalldisplay {font-family: inherit; font-size: smaller}
  45. pre.smallexample {font-size: smaller}
  46. pre.smallformat {font-family: inherit; font-size: smaller}
  47. pre.smalllisp {font-size: smaller}
  48. span.nocodebreak {white-space:nowrap}
  49. span.nolinebreak {white-space:nowrap}
  50. span.roman {font-family:serif; font-weight:normal}
  51. span.sansserif {font-family:sans-serif; font-weight:normal}
  52. ul.no-bullet {list-style: none}
  53. -->
  54. </style>
  55. </head>
  56. <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  57. <a name="Arrays"></a>
  58. <div class="header">
  59. <p>
  60. Next: <a href="Strings.html#Strings" accesskey="n" rel="next">Strings</a>, Previous: <a href="Subranges.html#Subranges" accesskey="p" rel="prev">Subranges</a>, Up: <a href="Types.html#Types" accesskey="u" rel="up">Types</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Symbol-Types-Index.html#Symbol-Types-Index" title="Index" rel="index">Index</a>]</p>
  61. </div>
  62. <hr>
  63. <a name="Array-Types"></a>
  64. <h3 class="section">5.5 Array Types</h3>
  65. <p>Arrays use the &lsquo;<samp>a</samp>&rsquo; type descriptor. Following the type descriptor
  66. is the type of the index and the type of the array elements. If the
  67. index type is a range type, it ends in a semicolon; otherwise
  68. (for example, if it is a type reference), there does not
  69. appear to be any way to tell where the types are separated. In an
  70. effort to clean up this mess, IBM documents the two types as being
  71. separated by a semicolon, and a range type as not ending in a semicolon
  72. (but this is not right for range types which are not array indexes,
  73. see <a href="Subranges.html#Subranges">Subranges</a>). I think probably the best solution is to specify
  74. that a semicolon ends a range type, and that the index type and element
  75. type of an array are separated by a semicolon, but that if the index
  76. type is a range type, the extra semicolon can be omitted. GDB (at least
  77. through version 4.9) doesn&rsquo;t support any kind of index type other than a
  78. range anyway; I&rsquo;m not sure about dbx.
  79. </p>
  80. <p>It is well established, and widely used, that the type of the index,
  81. unlike most types found in the stabs, is merely a type definition, not
  82. type information (see <a href="String-Field.html#String-Field">String Field</a>) (that is, it need not start with
  83. &lsquo;<samp><var>type-number</var>=</samp>&rsquo; if it is defining a new type). According to a
  84. comment in GDB, this is also true of the type of the array elements; it
  85. gives &lsquo;<samp>ar1;1;10;ar1;1;10;4</samp>&rsquo; as a legitimate way to express a two
  86. dimensional array. According to AIX documentation, the element type
  87. must be type information. GDB accepts either.
  88. </p>
  89. <p>The type of the index is often a range type, expressed as the type
  90. descriptor &lsquo;<samp>r</samp>&rsquo; and some parameters. It defines the size of the
  91. array. In the example below, the range &lsquo;<samp>r1;0;2;</samp>&rsquo; defines an index
  92. type which is a subrange of type 1 (integer), with a lower bound of 0
  93. and an upper bound of 2. This defines the valid range of subscripts of
  94. a three-element C array.
  95. </p>
  96. <p>For example, the definition:
  97. </p>
  98. <div class="example">
  99. <pre class="example">char char_vec[3] = {'a','b','c'};
  100. </pre></div>
  101. <p>produces the output:
  102. </p>
  103. <div class="example">
  104. <pre class="example">.stabs &quot;char_vec:G19=ar1;0;2;2&quot;,32,0,0,0
  105. .global _char_vec
  106. .align 4
  107. _char_vec:
  108. .byte 97
  109. .byte 98
  110. .byte 99
  111. </pre></div>
  112. <p>If an array is <em>packed</em>, the elements are spaced more
  113. closely than normal, saving memory at the expense of speed. For
  114. example, an array of 3-byte objects might, if unpacked, have each
  115. element aligned on a 4-byte boundary, but if packed, have no padding.
  116. One way to specify that something is packed is with type attributes
  117. (see <a href="String-Field.html#String-Field">String Field</a>). In the case of arrays, another is to use the
  118. &lsquo;<samp>P</samp>&rsquo; type descriptor instead of &lsquo;<samp>a</samp>&rsquo;. Other than specifying a
  119. packed array, &lsquo;<samp>P</samp>&rsquo; is identical to &lsquo;<samp>a</samp>&rsquo;.
  120. </p>
  121. <p>An open array is represented by the &lsquo;<samp>A</samp>&rsquo; type descriptor followed by
  122. type information specifying the type of the array elements.
  123. </p>
  124. <p>An N-dimensional dynamic array is represented by
  125. </p>
  126. <div class="example">
  127. <pre class="example">D <var>dimensions</var> ; <var>type-information</var>
  128. </pre></div>
  129. <p><var>dimensions</var> is the number of dimensions; <var>type-information</var>
  130. specifies the type of the array elements.
  131. </p>
  132. <p>A subarray of an N-dimensional array is represented by
  133. </p>
  134. <div class="example">
  135. <pre class="example">E <var>dimensions</var> ; <var>type-information</var>
  136. </pre></div>
  137. <p><var>dimensions</var> is the number of dimensions; <var>type-information</var>
  138. specifies the type of the array elements.
  139. </p>
  140. <hr>
  141. <div class="header">
  142. <p>
  143. Next: <a href="Strings.html#Strings" accesskey="n" rel="next">Strings</a>, Previous: <a href="Subranges.html#Subranges" accesskey="p" rel="prev">Subranges</a>, Up: <a href="Types.html#Types" accesskey="u" rel="up">Types</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Symbol-Types-Index.html#Symbol-Types-Index" title="Index" rel="index">Index</a>]</p>
  144. </div>
  145. </body>
  146. </html>