title: Array by reference length in C++
body: <blockquote>
    <p><strong>Possible Duplicate:</strong>
    <a href="https://stackoverflow.com/questions/720077/calculating-size-of-an-array">Calculating size of an array</a></p>
  </blockquote>
  
  
  
  <p>This question has been asked before, but I want to confirm it. Let's say I have the following C++ function:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdin.h&gt;
  #define length(a) sizeof(a)/sizeof(a[0])
  
  int main()
  {
      double c[] = {1.0, 2.0, 3.0};
      printf("%d\n", getLength(c));
      return 0;
  }
  
  int getLength(double c[]) { return length(c);}
  </code></pre>
  
  <p>This should return the wrong value because size of will return the size of the pointer as opposed to the size of the array being pointed at. This:</p>
  
  <pre><code>template&lt;typename T, int size&gt;
  int length(T(&amp;)[size]){return size;}
  </code></pre>
  
  <p>I know it works directly, but I want to know if I can somehow call it indirectly i.e. via a helper function. I understand that two possible alternatives are to either store the length of the array in a separate slot or use a vector, but what I want to know is:</p>
  
  <p>Given a function getLength:</p>
  
  <pre><code>getLength(double arr[])
  {
  ...
  }
  </code></pre>
  
  <p>Is there a way to compute the length of <code>arr</code> without passing any more information?</p>