You can try this ...
#include <cstdio> void print_array(int b[], size_t N) { for (int i = 0; i < N; ++i) printf("%d ", b[i]); printf("\n"); } template <size_t N> inline void print_array(int (&b)[N]) { // could have loop here, but inline forwarding to // single function eliminates code bloat... print_array(b, N); } int main() { int a[] = { 1, 2 }; int b[] = { }; int c[] = { 1, 2, 3, 4, 5 }; print_array(a); // print_array(b); print_array(c); }
... interesting b does not work ...
array_size.cc: In function `int main()': array_size.cc:19: error: no matching function for call to `print_array(int[0u])'
JoshD points out in comments below arrays of size re 0 of size (GCC extension) and above that size.
Tony delroy
source share