Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added array docs

  • Loading branch information...
commit 5cf3908e57ba079d832e431b39513128bb658bb9 1 parent 835636e
@rinon rinon authored
Showing with 33 additions and 0 deletions.
  1. +33 −0 docs/index.html
View
33 docs/index.html
@@ -199,6 +199,39 @@
trace("x = " + x + ", y = " + y);</pre>
+<h4>Arrays</h4>
+
+<p>
+ Typed arrays can be allocated on both the heap and the stack. Stack
+ allocated arrays must, as in C, be fixed length. Heap allocated
+ arrays use a similar syntax to C++ dynamic arrays and their size may
+ be computed at runtime.
+</p>
+
+<pre class="example">
+
+// Stack allocated, fixed size
+let int arr[100];
+arr[5] = 42;
+trace(arr[5]);
+
+// Heap allocated, dynamic size
+for (let int i=1; i <= 10; i++) {
+ let int *heapArr = new int[i];
+ arr[i-1] = i;
+ trace(i + ": " + arr[i-1]);
+}
+
+// Stack allocated array inside a struct
+struct ArrayStruct {
+ int arr[10];
+};
+
+let ArrayStruct s;
+s.arr[0] = 42;
+trace(s.arr[0]);
+</pre>
+
<h2>Objects and Memory</h2>
<p>
Please sign in to comment.
Something went wrong with that request. Please try again.