You might notice that the above code doesn't compile, this is the error:
cannot convert parameter 2 from 'BYTE ' to 'BYTE *'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Even after some search I couldn't really find an answer to my problem, how do I pass the const BYTE array which I declared above in the function as a parameter (or what structure do I need to set for the function as a parameter)?
In any case your function is declared incorrectly because it is not given numbers of column and rows in the array.
Nothing is wrong in the declaration of the function if the size of array is not specified. It depends on the user/programmer how he process the array. What I mean to say is, we cannot call this kind of code as incorrect.
function( reinterpret_cast<BYTE **>( original ), 2, 4 );
for 'C' style code, its not necessary to use a C++ cast. A normal C style cast will do the work.
No one can call it wrong (neither syntactically nor logically unless someone finds a bug in the code) and neither its the only way to tell a function the bounds of an array. You are free to think your way. :-)
Right. So When nothing is specified, its better to keep the code simple and use simple constructs.
1) I can't use this code with const, if I do so the compiler says
'reinterpret_cast' : cannot convert from 'const BYTE ' to 'BYTE **'
1> Conversion loses qualifiers
If I remove the const modifiers however, the code compiles fine
2) If I compile the code as mentioned above, the program crashes when I try to access the array in the function. It does this only when I use the Release build option in VS2010, if I set it to Debug I can access it without trouble.
What does BYTE** have to do with BYTE? They are two completely unrelated types. Reinterpreting one as another doesn't change that.
A pointer to a pointer to an element can be used (and is often used in C) when dealing with arrays of pointers to (elements of) arrays, but you aren't dealing with that at all, you're dealing with a 2D array.