PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : C - Präprozessor #defines abfragen



stefan-tiger
04-01-2008, 15:56
Hallo,

ich möchte folgendes:



#define CAT 0x01
#define DOG 0x02

#define ANIMAL EAGLE

...

#ifdef ANIMAL
#if ANIMAL==CAT
//do something
#elif ANIMAL==DOG
//do something other
#else
#error no valid animal set
#endif
#else
#error ANIMAL not set
#endif


Das Problem, es funktioniert nicht, also die Nachricht "#error no valid animal set" erscheint nicht.

ContainerDriver
04-01-2008, 16:12
Also hier funktioniert es.


florian@leuchtturm1:~$ cat pre.c
#define CAT 0x01
#define DOG 0x02

#define ANIMAL EAGLE

#ifdef ANIMAL
#if ANIMAL==CAT
//do something
#elif ANIMAL==DOG
//do something other
#else
#error no valid animal set
#endif
#else
#error ANIMAL not set
#endif

int main(void)
{
return 0;
}
florian@leuchtturm1:~$ gcc -o pre pre.c
pre.c:12:8: error: #error no valid animal set
florian@leuchtturm1:~$

stefan-tiger
04-01-2008, 16:54
Also hier funktioniert es.

...
pre.c:12:8: error: #error no valid animal set
...


Ja, danke. Bei mir gehts jetzt auch, hatte nen Fehler drin.

Wieso steht bei dir das "#error" auf der Konsole da?

ContainerDriver
04-01-2008, 17:04
Mmmmh, keine Ahnung :)

gcc --version sagt


gcc (GCC) 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
. Was hast du?

stefan-tiger
04-01-2008, 17:30
Mmmmh, keine Ahnung :)

gcc --version sagt


gcc (GCC) 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
. Was hast du?

Nen C-Compiler für nen Mikrocontroller :-) kann man nicht vergleichen. Sieht nur seltsam aus wenn das erscheint.

jeebee
04-01-2008, 23:29
Ist halt gcc. Dann sieht man das dies ein expliziter Präprozessor-Fehler und nicht ein "normaler" Fehler ist.