Sarath wrote:
Why the following happening?
UINT m_uArrXpos[4][7];
UINT **p = m_uArrXposSchema; // Failed to compile
What ever "m_uArrXposSchema" is, it isn't a "UINT**" (whatever "UINT" is).
UINT **p = (UINT**)m_uArrXposSchema; // Success compilation
You lied to the compiler.
--
Ian Collins.
Another funniest thing is that,
UINT m_uArrXpos[4][7];
UINT **p = m_uArrXpos; // Failed to compile
UINT **p = (UINT**)m_uArrXpos; // Success compilation
UINT **p = static_cast<UINT**>(m_uArrXpos); // Failed to compile
What it makes in difference static_cast and C style cast?
I'm using Visual C++ 6.0 Compiler
You are using a two dimensional array and not a pointer array. A
two dimensional array dont have a "**". Suppose the location given in
m_uArrXpos is 0x0012fef4. the value at this location will not be an
address. Insted it will be a value of the m_uArrXpos[0][0], So
defenitly a pointer is made to an invalid location. Even though the C
style cast works it will be a junk pointer. You cant use it out.
Compiler prevents this casting untill and otherwise you force to do
the casting.
Thanks,
Amal P.- Hide quoted text -
Hmmm... Seems like to learn everything from start
You mean unlearn. You are being confused because of too much code
hiding the details about the type involved. If you declare a 2D array
of unsigned integers, the elements are unsigned integers, not
pointers.
It is recommended not to hide pointers behind decorations. You'll find
some platforms that use these decorations to isolate your code from
any future changes they make as well as hide their implementations.
That doesn't mean you should be hiding your code from yourself.
#include <iostream>
typedef unsigned UINT; // no problem
typedef UINT* PTR; // this is ugly
typedef UINT** PTRPTR; // this is mischievious
int main()
{
// a container of primitives
UINT Arr[2][2];
Arr[0][0] = 99;
Arr[1][1] = 88;
unsigned* p = &Arr[0][0];
std::cout << *p << std::endl; // 99
p = &Arr[1][1];
std::cout << *p << std::endl; // 88
// a container of pointers
PTR Pointers[2][2]; // all point to nothing
Pointers[0][0] = &Arr[0][0]; // ok
unsigned* pu = Pointers[0][0];
std::cout << *pu << std::endl; // 99
// a container of pointers to pointers
PTRPTR PtrPtr[2][2]; // all point to invalid pointers
PtrPtr[0][0] = &Pointers[0][0]; // ok, ptr set to a valid ptr
unsigned** ppu = PtrPtr[0][0];
std::cout << **ppu << std::endl; // 99
}