0

My code below is trying to pass a multidimensional array to another function to perform certain tasks on it however it always produces the following error which I can't understand why. Everywhere I have look online states it was people using the '&' to pass the array parameter but I don't do that.

pong.c:48:17: warning: passing argument 1 of 'render' from incompatible pointer type [enabled by default] 
  case PAINT:     
             render(new_frame, argv[1], test_screen_size_x,test_screen_size_y);

My code:

void render(char *new_frame, char *out_frame, int screen_size_x, int screen_size_y);

int main(int argc, char **argv)
{
    int state  = START;     // Holds the current state of the state machine

    if(argc > 1){
        int test_screen_size_x;
        int test_screen_size_y;

        test_screen_size_x = *argv[2];  // int screen_size_x
        test_screen_size_y = *argv[3];  // int screen_size_y
        char new_frame[test_screen_size_x][test_screen_size_y];   

        while(1){
            switch(state){

                /*  START state - 
                */
                case START:     player_config(&player1, test_screen_size_y);
                            player_config(&player2, test_screen_size_y);

                            state = CALC;       // Move to the CALC state
                            break;

            /*  CALCULATION state - Performs all the game calculations
            */
            case CALC:      paddle(&player1, test_screen_size_y); // Calc paddle position of player 1
                            paddle(&player2, test_screen_size_y); // Calc paddle position of player 1

                            state = PAINT;       // Move to the PAINT state
                            break;

            /*  PAINT state - 
            */                         
            case PAINT:     render(new_frame, argv[1], test_screen_size_x, test_screen_size_y);

                            state = CALC;       // Move to the CALC state
                            break;    
        }
    }
    return (0);       
}


void render(char *new_frame, char *out_frame, int screen_size_x, int screen_size_y)
/*  Function creates the new frame
 */
{    
    memset(new_frame, 0, sizeof(new_frame[0][0]) * screen_size_x * screen_size_y);  // Fill multi-dimensional array full of zeros

    draw_dyn_object(&player1, new_frame);
    draw_dyn_object(&player2, new_frame);

    out_frame = new_frame;
}

...
Marmstrong
  • 1,686
  • 7
  • 30
  • 54
  • So it is telling you everything. `render` expecting to get `char*`, but you are giving it `char[][]`. – Eugene Sh. Apr 29 '15 at 21:45
  • @EugeneSh. Char * is a pointer and I thought passing an array passes the pointer to the first element of the array? – Marmstrong Apr 29 '15 at 21:47
  • The **value** of the pointers might be the same, but their type is different and incompatible, as the compiler suggesting. As you can see, it is not an error, it's a warning, so if you really want to and know what you are doing, you can try and ignore it. But I wouldn't recommend that. – Eugene Sh. Apr 29 '15 at 21:49

0 Answers0