cstringmultidimensional-arraymultiple-indirection

How many levels of indirection on Multidimensional Arrays are there?


I am using Microsoft Visual Studio Express 2013, trying to make this something... The code actually works out, but still, there is an error, with the code C4047: 'char *' differs in levels of indirection from 'char[24][50]'

Is that so?

Disregarding the warning, the programme works as I expected it to work with no issues. I am only trying to understand and learn what is going on behind. The (stale) warning indicates the line where I pass a multidimensional array in a function. Here's the arguments-line of that function:

void mass_assigner(
    WORD * translations,
    char * labels,
    char * PermBannedKeys,
    char * TempBannedKeys,
    char * Cooldowns
)
{ ... }

and here's how I call it from the main:

...
mass_assigner(
    translations,
    labels,
    PermBannedKeys,
    TempBannedKeys,
    Cooldowns
);
...

where labels is char labels[24][50] = { ... };

What is the problem really? As far as I know, a multidimensional array is not an array of arrays (which would have multiple levels of indirection), rather just an array (which has single level of indirection).


Solution

  • If you are passing a two-dimensional array to a function:

    int labels[NROWS][NCOLUMNS];
    f(labels);
    

    the function's declaration must match:

    void f(int labels[][NCOLUMNS])
    { ... }
    

    or

    void f(int (*ap)[NCOLUMNS]) /* ap is a pointer to an array */
    { ... }