I can declare animal_array1
and animal_array2
. First one on the stack, while the second one is ... well, still on the stack but this time declared as a function parameter. Here is a sample code:
#include <iostream>
using namespace std;
struct Animal
{
};
void test(Animal animal_array2[10])
{
Animal animal_array1[10];
if(sizeof(animal_array2) == sizeof(animal_array1))
cout << "Both sizes are equal. That's expected!" << endl;
else
cout << "Mhhh sizes are *NOT* equal. That wasn't expected at all!" << endl;
}
int main()
{
Animal unused_var[10];
test(unused_var);
}
The output is:
$./a.out
Mhhh sizes are *NOT* equal. That wasn't expected at all!
How can it be? Gcc bug? Or is it standard behavior? How can we get such streched results from the same apparent type?