undefined type or class 'bool' ?!?
-
Hi!
Ich hab mir gerade mit KDEvelop nen kleines app geschrieben, aber irgendwie kennt gcc die standard datentypen nicht?!bash-2.05b$ make if gcc -DHAVE_CONFIG_H -I. -I/home/cncmasta/indexit/src -I.. -g -O2 -MT indexit.o -MD -MP -MF ".deps/indexit.Tpo" \ -c -o indexit.o `test -f 'indexit.c' || echo '/home/cncmasta/indexit/src/'`indexit.c; \ then mv ".deps/indexit.Tpo" ".deps/indexit.Po"; \ else rm -f ".deps/indexit.Tpo"; exit 1; \ fi In file included from indexit.c:18: indexit_structs.h:72: parse error before "bFirstTime" indexit.c:30: parse error before "bFirstTime" indexit.c: In function `menu': indexit.c:32: `bFirstTime' undeclared (first use in this function) indexit.c:32: (Each undeclared identifier is reported only once indexit.c:32: for each function it appears in.) indexit.c:51: `false' undeclared (first use in this function) indexit.c: In function `main': indexit.c:80: `true' undeclared (first use in this function) indexit.c:86:1: warning: no newline at end of file make: *** [indexit.o] Error 1 bash-2.05b$
irgendwo stand da noch "parser error before int" aber da ist definitiv keiner!
hab nur stdio.h und stdlib.h included!greets,
cNc
-
bool ist kein Standard-Datentyp in C. Wenn du bool, true und false verwenden willst, mußt du <stdbool.h> einbinden.
-
noch ne frage:
so bekomm ich doch ein mehrdimensionales array oder?char **chDatabases = (char*)malloc(sizeof(char*) * iNumDBs); for(i = 0; i < iNumDBs; i++) { chDatabases[i] = (char*)malloc(sizeof(char) * MAX_CHAR_LENGHT); }
oder?
greets,
cNc
-
der Ansatz ist richtig. Aber du solltest beachten, dass sizeof(char) eh immer 1 zurückliefert und das man den Rückgabewert von malloc nicht casten sollte.
BTW.
der Standard Bool Typ ist in C (C99) _Bool in <stdbool.h> sind nur entspr. typedefs und constanten.
-
_Bool ist nur drin, weil viele alte Projekte bereits eigene bool-Typen definieren, und man die ja nicht alle wegschmeißen kann, nur weil C99 ein bool-keyword haben will. Für neue Sachen sollte man auf jeden Fall stdbool.h verwenden.
BTW: der Cast bei malloc ist falsch. Entweder gar nicht casten (das beste), oder zum richtigen Typ, was hier char** wäre. char* ist einfach Unfug.