One-dimensional-arrays.html 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <html lang="en">
  2. <head>
  3. <title>One dimensional arrays - avram - a virtual machine code interpreter</title>
  4. <meta http-equiv="Content-Type" content="text/html">
  5. <meta name="description" content="avram - a virtual machine code interpreter">
  6. <meta name="generator" content="makeinfo 4.13">
  7. <link title="Top" rel="start" href="index.html#Top">
  8. <link rel="up" href="Type-Conversions.html#Type-Conversions" title="Type Conversions">
  9. <link rel="prev" href="Primitive-types.html#Primitive-types" title="Primitive types">
  10. <link rel="next" href="Two-dimensional-arrays.html#Two-dimensional-arrays" title="Two dimensional arrays">
  11. <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
  12. <meta http-equiv="Content-Style-Type" content="text/css">
  13. <style type="text/css"><!--
  14. pre.display { font-family:inherit }
  15. pre.format { font-family:inherit }
  16. pre.smalldisplay { font-family:inherit; font-size:smaller }
  17. pre.smallformat { font-family:inherit; font-size:smaller }
  18. pre.smallexample { font-size:smaller }
  19. pre.smalllisp { font-size:smaller }
  20. span.sc { font-variant:small-caps }
  21. span.roman { font-family:serif; font-weight:normal; }
  22. span.sansserif { font-family:sans-serif; font-weight:normal; }
  23. --></style>
  24. </head>
  25. <body>
  26. <div class="node">
  27. <a name="One-dimensional-arrays"></a>
  28. <p>
  29. Next:&nbsp;<a rel="next" accesskey="n" href="Two-dimensional-arrays.html#Two-dimensional-arrays">Two dimensional arrays</a>,
  30. Previous:&nbsp;<a rel="previous" accesskey="p" href="Primitive-types.html#Primitive-types">Primitive types</a>,
  31. Up:&nbsp;<a rel="up" accesskey="u" href="Type-Conversions.html#Type-Conversions">Type Conversions</a>
  32. <hr>
  33. </div>
  34. <h5 class="subsubsection">3.1.4.2 One dimensional arrays</h5>
  35. <p>A couple of functions declared in <samp><span class="file">matcon.h</span></samp> are concerned mainly
  36. with one dimensional arrays or vectors. They have been used for
  37. <a name="index-arrays-445"></a>vectors of double precision and complex numbers, but are applicable to
  38. <a name="index-vectors-446"></a>any base type that is contiguous and of a fixed size.
  39. <p>The motivation for these functions is to enable a developer to present
  40. an API to virtual code applications wherein external library functions
  41. operating natively on one dimensional arrays of numbers are seen from
  42. the virtual side to operate on lists of numbers. Lists are the
  43. preferred container for interoperability with virtual code
  44. applications.
  45. <div class="defun">
  46. &mdash; Function: void <b>*avm_vector_of_list</b> (<var>list operand, size_t item_size, list *message, int *fault</var>)<var><a name="index-g_t_002aavm_005fvector_005fof_005flist-447"></a></var><br>
  47. <blockquote><p>This function calls <code>avm_value_of_list</code> (<a href="Primitive-types.html#Primitive-types">Primitive types</a>)
  48. for each item of the <var>operand</var> and puts all the values together
  49. into one contiguous block, whose address is returned.
  50. <p>The given <var>item_size</var> is required to be the lengths of the items,
  51. all necessarily equal, and is required only for validation. For
  52. example, <var>item_size</var> is 8 for a list of double precision numbers,
  53. because they occupy 8 bytes each and are represented as lists of length 8.
  54. <p>The total number of bytes allocated is the product of <var>item_size</var>
  55. and the length of the <var>operand</var>. Unlike the case of
  56. <code>avm_value_of_list</code> (<a href="Primitive-types.html#Primitive-types">Primitive types</a>), the result returned
  57. by this function should be explicitly freed by the caller when no
  58. longer needed.
  59. <p>Any errors such as insufficient memory cause the integer referenced by
  60. <var>fault</var> to be assigned a non-zero value and the <var>message</var> to
  61. be assigned an error message represented as a list of strings. An
  62. error message of <code>&lt;'bad vector specification'&gt;</code> is possible in
  63. the case of an empty <var>operand</var> or one whose item lengths don't
  64. match the given <var>item_size</var>. Error messages caused by
  65. <code>avm_value_of_list</code> can also be generated by this function. Any
  66. non-empty error message should be reclaimed by the caller using
  67. <code>avm_dispose</code> (<a href="Simple-Operations.html#Simple-Operations">Simple Operations</a>). If an error occurs, a
  68. <code>NULL</code> pointer is returned.
  69. </p></blockquote></div>
  70. <div class="defun">
  71. &mdash; Function: list <b>avm_list_of_vector</b> (<var>void *vector, int num_items, size_t item_size, int *fault</var>)<var><a name="index-avm_005flist_005fof_005fvector-448"></a></var><br>
  72. <blockquote><p>This function takes it on faith that an array of dimension
  73. <var>num_items</var> in which each item occupies <var>item_size</var> bytes
  74. begins at the address given by <var>vector</var>. A list representation of
  75. each item in the array is constructed by the function
  76. <code>avm_list_of_value</code> (<a href="Primitive-types.html#Primitive-types">Primitive types</a>), and a list of all of
  77. the lists thus obtained in order of their position in the array is
  78. returned.
  79. <p>In the event of any errors caused by <code>avm_list_of_value</code> or
  80. errors due to insufficient memory, the error message is returned as
  81. the function result, and the integer referenced by <var>fault</var> is
  82. assigned a non-zero value. The error message is in the form of a list
  83. of character string representations. A segmentation fault is possible
  84. <a name="index-segmentation-fault-449"></a>if <var>vector</var> is not a valid pointer or if the array size implied by
  85. misspecified values of <var>num_items</var> and <var>item_size</var>
  86. exceeds its actual size.
  87. </p></blockquote></div>
  88. </body></html>