Link to home
Start Free TrialLog in
Avatar of neel3333
neel3333

asked on

Convert unsigned char** to unsigned char*

unsigned char **test;
unsigned char *result = test;

I want single pointer result to have same content as double pointer test.

The question is how can I typecast double pointer to single pointer.

Thanks
Avatar of bcladd
bcladd

You can't BUT you can have it point at the same spot test points:

result = *test;

Note that this will point at the exact same memory and you should copy it if you are going to play games with it.

Hope this helps,
-bcl
ASKER CERTIFIED SOLUTION
Avatar of itsmeandnobodyelse
itsmeandnobodyelse
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
itsmeandnobodyelse's 2D matrix is a good example of a valid cast. However, C-style casts can hide a multitude of sins, and we should really use reinterpret_cast<> to confess our sins in C++, when we are saying to the compiler that the programmer knows best.

        unsigned char matrix[10][20];
        unsigned char *result1 = static_cast<unsigned char*>(matrix); /* The compiler throws an error - this *isn't* a straight-forward cast! */
        unsigned char *result2 = reinterpret_cast<unsigned char*>(matrix); /* This compiles, but doesn't it make you feel evil? reinterpret_cast<> says that the programmer knows what he is doing*/
        unsigned char *result3 = (unsigned char*)matrix; /* Sneaky C-style cast. Bitter experience gets these to work */