
AMDG Zachary Turner wrote:
I have a question about the following code:
typedef void(intArrayParamFunc)(int[]); typedef void(intPtrParamFunc)(int*);
BOOST_STATIC_ASSERT((boost::is_same
::value)); BOOST_STATIC_ASSERT((boost::is_same ::value)); cout << typeid(intArrayParamFunc).name() << endl; cout << typeid(intPtrParamFunc).name() << endl;
cout << typeid(int*).name() << endl; cout << typeid(int[]).name() << endl;
The first assert compiles but the second fails, which means that boost::is_same<> thinks that int* and int[] are different, but void(int[]) and void(int*) are the same. Why is this?
The typeids print out the following:
void __cdecl(int * const) void __cdecl(int *) int * int [0]
I'm using Visual Studio 2008. I notice that typeid tells me that intArrayParamFunc is void(int* const). So why does boost::is_same<> compare them equal? Surely void(int* const) should not be the same type as void(int*).
Yes, it is the same. They are the same because the two signatures are equivalent at the call site. The only difference between void f(const int); and void f(int); is that in the first case f can modify its arguments. Since the argument is passed by value, this has no impact on the caller.
Unless this is just some obscure language subtlety I'm not aware of. So is this a bug in boost::is_same<>, a bug in my compiler, or no bugs at all and everything is working perfectly?
Everything is working perfectly. An array argument to a function is really a pointer. In Christ, Steven Watanabe