dereferencing pointer to incomplete type [Gelöst]
-
@DirkB
nein es handelt sich um den inhalt aus einer Datei. Es wurden (noch) keine Funktionen in andere Dateien oder Header ausgelagert.
-
Das ergibt dann
x.c: In function ‘main’:
x.c:12:2: warning: implicit declaration of function ‘init_rand_matrix’ [-Wimplicit-function-declaration]
init_rand_matrix(&matrix1);
^~~~~~~~~~~~~~~~
x.c: At top level:
x.c:17:6: warning: conflicting types for ‘init_rand_matrix’
void init_rand_matrix(struct matrix *matrix1)
^~~~~~~~~~~~~~~~
x.c:12:2: note: previous implicit declaration of ‘init_rand_matrix’ was here
init_rand_matrix(&matrix1);
^~~~~~~~~~~~~~~~
x.c: In function ‘init_rand_matrix’:
x.c:25:37: warning: implicit declaration of function ‘rand’ [-Wimplicit-function-declaration]
matrix1 -> Array[i][j] = (double)rand()/RAND_MAX; // Hier ist der Compiler Fehler
^~~~
x.c:25:44: error: ‘RAND_MAX’ undeclared (first use in this function)
matrix1 -> Array[i][j] = (double)rand()/RAND_MAX; // Hier ist der Compiler Fehler
^~~~~~~~
x.c:25:44: note: each undeclared identifier is reported only once for each function it appears inDer von dir genannte Fehler lommt nicht vor.
-
Der von dir genannte Fehler lommt nicht vor.
mhhh dann muss ich wohl mal einen anderen Compiler zu rate ziehen
Dev C++ scheint an der Stelle etwas zu versagen.
-
Die Warnungen von manni66 kannst du beheben, indem du
- die nötigen Standardheader inkludierst
- die Funktion
main
an das Ende vom Code stellst
-
Ich glaube es ist einfacher wenn ich einmal den gesamten Code zur verfügung Stelle
#include <stdio.h> #include <stdlib.h> /* run this program using the console pauser or add your own getch, system("pause") or input loop */ neue_matrix(int n, int m) //kann erstmal ignoriert werden { } void init_rand_matrix(struct matrix *matrix1) { int i = 0, j = 0; for(i = 0; i<= 4; j++) { for(j = 0; j <= 5; j++) { matrix1 -> Array[i][j] = (double)rand()/RAND_MAX; } } } void print(struct matrix *matrix1 ) // kann auch ignoriert werden { int i = 0,j = 0; for(i = 0;i <= 4; i++) { for(j = 0; j <= 5; j++) { printf("%d", matrix1 ->Array[i][j]); } printf("\n"); } } struct matrix { double Array[5][6]; //double index = 0.0; //int *pZeiger = NULL; }; int main(int argc, char *argv[]) { struct matrix matrix1; init_rand_matrix(&matrix1); return 0; }
-
Entweder main nach unten oder eine Funktionsdeklaration darüber:
void init_rand_matrix(struct matrix *matrix1); int main(int argc, char *argv[]) { ... }
init_rand_matrix wird aber so nicht zurückkehren (Endlosschleife).
-
Tja, jetzt steht die Definition von matrix plötzlich hinter den Funktionen. Das isr der Fehler.
-
@SirRust Wenn der Compiler init_rand_matrix compiliert, kennt er den Aufbau der struct matrix noch nicht.
Der Compiler geht einmal durch den Code, von oben nach unten.
-
Ahhhh OK macht Sinn wenn man Struct Global nimmt .
Manchmal sieht man echt den Wald vor lauter Bäumen nicht.
Vielen Dank für die Hilfe
-
@SirRust
Die Definition des struct-Typs muss global sein.Die Definition der struct-Variable aber nicht.