Ich möchte eine Struktur initialisieren, die ich gemacht habe, aber ich bekomme Fehler und ich kann nicht verstehen, was sie verursacht hat. Ich arbeite an GCC mit ANSI C Flagge.C - Fehler beim Initialisieren der Struktur mit Array-Mitgliedern
Wenn jemand mir helfen kann zu verstehen, was das Problem ist, werde ich es sehr schätzen!
typedef struct _inst {
const char *name[NUM_OF_INSTRUCTIONS];
int codes[NUM_OF_INSTRUCTIONS];
int validParam[NUM_OF_INSTRUCTIONS];
} instructions;
instructions instructionsData;
instructionsData.name[] = {"mov", "cmp", "add", "sub", "not", "clr", "lea", "inc", "dec", "jmp", "bne", "red", "prn", "jsr", "rts", "stop"};
instructionsData.codes[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
instructionsData.validParam[] = {2, 2, 2, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 0, 0};
und die Fehler, die ich von gcc erhalten sind:
dataStructs.h:47:17: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘.’ token
instructionsData.name[] = {"mov", "cmp", "add", "sub", "not", "clr", "lea", "inc", "dec", "jmp", "bne", "red", "prn", "jsr", "rts", "stop"};
^
dataStructs.h:47:140: warning: ISO C does not allow extra ‘;’ outside of a function [-Wpedantic]
instructionsData.name[] = {"mov", "cmp", "add", "sub", "not", "clr", "lea", "inc", "dec", "jmp", "bne", "red", "prn", "jsr", "rts", "stop"};
^
dataStructs.h:48:17: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘.’ token
instructionsData.codes[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
^
dataStructs.h:48:82: warning: ISO C does not allow extra ‘;’ outside of a function [-Wpedantic]
instructionsData.codes[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
^
dataStructs.h:49:17: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘.’ token
instructionsData.validParam[] = {2, 2, 2, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 0, 0};
^
dataStructs.h:49:81: warning: ISO C does not allow extra ‘;’ outside of a function [-Wpedantic]
instructionsData.validParam[] = {2, 2, 2, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 0, 0};
Könnten Sie bitte den Code kopieren und einfügen und keine Screenshots hochladen? –
betrügen? https://Stackoverflow.com/a/41510479/2173917 –
@SouravGhosh obwohl Lösung ist das gleiche, ich denke, das Problem ist anders. Nicht ein Betrogener? –