Fehler: invalid use of undefined type
-
Folgender Code:
pspwamp_datatypes.c
[...] typedef struct { char * name; int num_albums; char ** albums; } artist_entry; [...]
main.c
[...] artist_entry* artist_list; artist_list = (artist_entry *)malloc(sizeof(artist_entry)); get_artists_from_server(sock, artist_list); [...]
pspwamp_commands.c
int get_artists_from_server(int socket, struct artist_entry * artist_list) { [...] artist_list = (artist_entry *)realloc(artist_list, atoi(num_artists)*sizeof(artist_entry)); [...] int i,j; for(i=0; i<atoi(num_artists); i++) { [...] artist_list[i].name = (char*)malloc(artist_name_lenght+1); //z.104 [...] } }
Folgender Fehler:
pspwamp_commands.c:104: error: invalid use of undefined type 'struct artist_entry'
Kann jemand abhelfen?
-
das ist nicht zeile 104. zeile 104 ist 8 zeilen drueber. du hast ein "struct" im sizeof() ausgelassen.
-
Es ist Zeile 104. Wenn ich aus dem sizeof sizeof(struct artist_entry) mache bekomme ich immer noch die selben Fehlermeldeungen wie vorher
Hier mal die ganze Liste falls was davon wichtig sein sollte
pspwamp_commands.c:91: error: invalid application of 'sizeof' to incomplete type
'struct artist_entry'
pspwamp_commands.c:91: warning: assignment from incompatible pointer type
pspwamp_commands.c:104: error: invalid use of undefined type 'struct artist_entr
y'
pspwamp_commands.c:104: error: dereferencing pointer to incomplete type
pspwamp_commands.c:105: error: invalid use of undefined type 'struct artist_entr
y'
pspwamp_commands.c:105: error: dereferencing pointer to incomplete type
pspwamp_commands.c:106: error: invalid use of undefined type 'struct artist_entr
y'
pspwamp_commands.c:106: error: dereferencing pointer to incomplete type
pspwamp_commands.c:106: error: syntax error before ';' token
pspwamp_commands.c:113: error: invalid use of undefined type 'struct artist_entr
y'
pspwamp_commands.c:113: error: dereferencing pointer to incomplete type
pspwamp_commands.c:117: error: invalid use of undefined type 'struct artist_entr
y'
pspwamp_commands.c:117: error: dereferencing pointer to incomplete type
pspwamp_commands.c:129: error: invalid use of undefined type 'struct artist_entr
y'
pspwamp_commands.c:129: error: dereferencing pointer to incomplete type
pspwamp_commands.c:130: error: invalid use of undefined type 'struct artist_entr
y'
pspwamp_commands.c:130: error: dereferencing pointer to incomplete type
pspwamp_commands.c:131: error: invalid use of undefined type 'struct artist_entr
y'
pspwamp_commands.c:131: error: dereferencing pointer to incomplete type
pspwamp_commands.c:134: error: invalid use of undefined type 'struct artist_entr
y'
pspwamp_commands.c:134: error: dereferencing pointer to incomplete type
-
Wie kommst du darauf, dass ein Typ, der in pspwamp_datatypes.c definiert wurde, in pspwamp_commands.c bekannt sein sollte? Von allein geht das nicht. Hast du keine Headerdateien?
-
MFK schrieb:
Wie kommst du darauf, dass ein Typ, der in pspwamp_datatypes.c definiert wurde, in pspwamp_commands.c bekannt sein sollte?
Weil ich's einbinde...
-
nein. man "bindet" keine *.c dateien ein.
du packst die strukt definition in eine header datei und inkludierst die header datei.
sonst kommst du wegen der odr in teufels kueche.
-
ich habe jetzt die datei mit dem struct in pspwamp_datatypes.h umgenannt und wie vorher per #include eingebunden, oder von mir aus auch includiert.
pspwamp_datatypes.h
#ifndef PSPWAMP_DATATYPES #define PSPWAMP_DATATYPES typedef struct { char * name; int num_albums; char ** albums; } artist_entry; #endif
pspwamp_commands.c und main.c enthalten jeweils
#include "pspwamp_datatypes.h"
Gleiche Meldungen
-
typedef struct { ... } artist_entry; int get_artists_from_server(int socket, struct artist_entry * artist_list)
entscheide dich bitte fuer struct oder typedef
-
Ich hatte am Anfang nur
struct { ... } artist_entry;
benutzt, das ging nicht, da sagte man mir in einem forum ich sollte typedef davor klatschen, dann gings. Jetzt geht es aber auch ohne.
Jetzt, ohne typedef, nur mit struct {...} name; habe ich aber immer noch die selben Fehlermeldungen
Lösche ich das struct aus den Parametern bekomme ich folgende Fehlermeldungen
pspwamp_commands.c:10: error: syntax error before 'artist_entry'
pspwamp_commands.c: In function 'get_artists_from_server':
pspwamp_commands.c:38: warning: passing argument 1 of 'send' makes integer from
pointer without a cast
pspwamp_commands.c:44: warning: passing argument 1 of 'recv' makes integer from
pointer without a cast
pspwamp_commands.c:67: warning: passing argument 1 of 'recv' makes integer from
pointer without a cast
pspwamp_commands.c:91: error: 'artist_list' undeclared (first use in this functi
on)
pspwamp_commands.c:91: error: (Each undeclared identifier is reported only once
pspwamp_commands.c:91: error: for each function it appears in.)
pspwamp_commands.c:91: error: syntax error before ')' token
pspwamp_commands.c:106: error: syntax error before ';' tokenIch weiß ich stochere herum, aber ich bin noch nicht lange dabei
edit:
mittypedef struct artist_entry_struct { char * name; int num_albums; char ** albums; } artist_entry;
funtioniert's auch nicht
-
Mal langsam:
struct{...} entry;
definiert einen unbenannten struct-Typ und davon eine Variable namens 'entry'
struct entry{...};
definiert einen Typ namens 'struct entry' - den du so im Quellcode ansprechen kannst
typedef struct{...} entry;
definiert 'entry' als Bezeichnung für den (jetzt nicht mehr) namenlosen struct-Typ - den kannst (und mußt) du ohne struct-Schlüsselwort ansprechen.
(Anmerkung: in C++ wären die letzten beiden Varianten gleichwertig, in C jedoch nicht)
typedef struct entry_t{...} entry;
ist eine Kombination aus Variante 2 und 3 - du kannst den Typ entweder als 'struct entry_t' oder als 'entry' ansprechen.
Auf dein Problem angewandt: Du hast die Varianten 2 und 3 miteinander vermischt. Wenn du in deiner Funktionsdefinition das 'struct' weglässt, sollte es eigentlich funktionieren.
-
Gut, Danke, funktioniert