Array in keil c vorbei gibt C182, C235 Warnungen (Zeiger auf verschiedene Objekte, Parameter 2 verschiedene Typen)

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

  •  13-10-2019
  •  | 
  •  

Frage

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

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

Hallo,

In Keil, der obige Code gibt Warnung C182 für den Aufruf von foo und es gibt in der Definition von foo C235 warnen. Aber es scheint ++ fein in VC zu arbeiten. Irgendwelche Ideen, warum und wie zu lösen?

Danke!

War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top