passing array in keil c gives C182, c235 warnings (pointer to different objects, parameter 2 different types)

StackOverflow https://stackoverflow.com/questions/4742861

  •  13-10-2019
  •  | 
  •  

Question

int main ()
{
    int arr[2][3];
    foo (arr);
    return 0;
}

void foo(int (*arr)[3])
{
    **arr = 0;
}

Hi,

In Keil, the above code gives warning C182 for the call to foo and it gives warning c235 in the definition of foo. But it seems to work fine in VC++. Any ideas why and how to resolve?

Thanks!

Was it helpful?

Solution

Provide a prototype for the function so the compiler knows what's going on when the call is made:

void foo(int (*arr)[3]);

int main () 
{
    int arr[2][3]; 

    foo (arr); 

    return 0; 
}

void foo(int (*arr)[3]) 
{ 
    **arr = 0;
}

Without the prototype the compiler must make assumptions about the parameter(s) passed and what the function returns. The compiler may or may not issue warnings about this depending on the version of the compiler and the compiler settings.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top