I've managed to figure out what's going on although I'd still appreciate it if someone has anything to add
Code:
void a(const int *test);
void b(const int test[]);
void c(const int test[10]);
Turns out these three function declarations are identical and in each case, passing an array will result in the array decaying into a pointer. The compiler ignores the 10 I've added in declaration of c and this was the source of confusion for me.
The only way to pass an actual array (without decay) is by using reference:
Code:
void d(const int(&test)[10])
The compiler will complain if I don't specify the size in declaration of d, or if I pass an array that has size other than 10.
Alternatively I can pass a pointer to an array:
Code:
void alternative(const int (*test)[10]){
std::cout << typeid(*test).name() << '\n';
std::cout << sizeof(*test) << "\n";
}
Here I can only pass an int array of size 10. typeid().name() gives int const [10] and sizeof() gives 40 on my machine.
Also learnt that even though the compiler ignores the specified bound in the case of c, it actually only ignores the first (left-most) bound.
Code:
void e(const int test[32][32][32]){ // identical to void e(const int test[][32][32])
std::cout << typeid(test).name() << '\n';
std::cout << sizeof(test) << "\n";
}
int main()
{
int test[64][32][32]; // 64 can be replaced by any valid value (>0) but the other two sizes must be 32
e(test);
return 0;
}
This prints int const (*)[32][32] and 4.