Array length: Difference between revisions

Content added Content deleted
({{header|Insitux}} implementation)
(Added S-BASIC example)
Line 2,726: Line 2,726:
}
}
</syntaxhighlight>
</syntaxhighlight>

=={{header|S-BASIC}}==
Finding the size of an S-BASIC array at run-time is convoluted, to say the least, but it can be done. (It would also generally be pointless, since the size of an array is fixed - and thus presumably known - at compile time.) Each array has an associated data structure (referred to in the documentation as "SPEC") containing information such as the number of dimensions, the size of an array element, the size of each dimension, and so on. The address of the SPEC for an array can be obtained using the LOCATION statement. For a single-dimension array, the number of elements will be found five bytes into the structure, at a point described in the documentation as the "dope vector".
<syntaxhighlight lang = "BASIC">
dim string animals(2) rem here is our array
var array_struct_address = integer
based array_size = integer

animals(1) = "ardvark"
animals(2) = "bison"

location spec array_struct_address = animals
base array_size at array_struct_address + 5

print "Size of array ="; array_size

end
</syntaxhighlight>
{{out}}
<pre>
Size of array = 2
</pre>


=={{header|Scala}}==
=={{header|Scala}}==