We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hello, I am trying unsuccessfully to use directive compilers such as #ifdef #elif with Keil C v6.12 as follows: #if defined (TOTO) #include "toto.h" #elif defined (TATA) #include "tata.h" #elif defined (TITI) #include "titi.h" #endif I think it should work, but it doesn't. Before I was using : #if defined (TOTO) #include "toto.h" #endif #if defined (TATA) #include "tata.h" #endif #if defined (TITI) #include "titi.h" #endif But in some cases in my code that is not possible to do so, I have to use a #elif. If someone has experienced the same problem.... Thank you for your help Best regards, Christophe
I'm not used to work with the Keil compiler but I think you should use #ifdef #else #endif
The v6.14 compiler doesn't complain. What exactly do you mean by, "it doesn't work" - do you get compile errors? - does it not include the files you expect? - or what?
#elif is perfectly standard - see K&R chapter 4. (also Chapter 4 in the C51 User's Guide!) Note that there isn't a #elifdef, but v6.12 will silently ignore it if you try!
to check what the preprocessor is actually doing, use the PREPRINT option. (Check 'C Preprocessor Listing' on the 'Listing' tab in uVision) Unfortunately, Keil doesn't have an option to keep comments in the preprocessor listing. Many other compilers do have this, so it might be worth testing the logic of your #ifs on another compiler, if you have one (eg, Borland, MSVC)
Hello, thank you for answering me. I have compile errors because the file is not included. But I don't have compile errors on #elif statement. It was working with : #ifdef AA #include #endif #ifdef BB #include #endif #ifdef CC #include #endif But I would like not to test AA, BB or CC. If AA is OK, then not test BB or CC. Best regards, Christophe
which case(s) work? which don't? Are you sure that the cases are really mutually exclusive? Are you sure that the correct symbol is defined?
Keil compiler has a bug in that all #elifs are automatically of the "#if" nature, so the following thing won't work #ifdef TARGET_IS_ME ... #elif TARGET_IS_YOU // BUG !! must use defined(TARGET_IS_YOU) ... #endif /*I find one keil bug per month */