itsanjan / arduino

Automatically exported from code.google.com/p/arduino
Other
0 stars 0 forks source link

Array length command #539

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What change would like to see?

It would be useful to have an array length command.  Is is enough to do 
something as simple as:

int length = sizeof(array)/sizeof(int);  ?

Original issue reported on code.google.com by tom.i...@gmail.com on 9 May 2011 at 10:41

GoogleCodeExporter commented 9 years ago
The problem is that this only works in the scope in which the array was 
defined.  If you pass an array to a function, sizeof(array) doesn't work in the 
function: it returns the size of a pointer, which is unrelated to the number of 
elements in the array.  Unfortunately, this is one of those C limitations that 
we inherit.  

Original comment by dmel...@gmail.com on 9 May 2011 at 3:24