If you are in C ++, reasonable options are:
- use
boost::multi_array (recommended) or - create your own class of 2D arrays. Well, you donβt have to, but encapsulating 2D array logic in a class is useful and makes the code clean.
Manual indexing of a 2D array will look like this:
void func(int* arrayData, int arrayWidth) {
But seriously, either wrap it in a class, or enjoy the fact that Boost already has this class, ready for you. Indexing this manually is tedious and makes the code more unclean and error prone.
change
http://gcc.gnu.org/onlinedocs/gcc/Variable-Length.html says that C99 has another solution for you:
void func(int len, int array[len][len]) { // notice how the first parameter is used in the definition of second parameter }
Should also work in C ++ compilers, but I have never used this approach.
source share