Keil stm32 compiler issue
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2015-09-30 2:23 AM
Hi every one
I get a strange bug with a subject. It's in a relation to the preprocessor directives. There is a few definition in a header file (adc.h):#define ADC_NUM_OF_BITS_12 (0)
#define ADC_NUM_OF_BITS_10 (1) #define ADC_NUM_OF_BITS_8 (0)There is a C code in the adc,c file:
uint8_t Tst12= 50/*, Tst10= 50*/, Tst8= 50; void Tst(void) { #if (ADC_NUM_OF_BITS_12 > 0) ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b; Tst12= 12; #endif #if ((defined ADC_NUM_OF_BITS_10) && (ADC_NUM_OF_BITS_10 > 0)) ADC_InitStructure.ADC_Resolution = ADC_Resolution_10b; Tst10= 10; #endif #if (ADC_NUM_OF_BITS_8 > 0) ADC_InitStructure.ADC_Resolution = ADC_Resolution_8b; Tst8= 8; #endif sprintf(uartStr, ''**** %i \t %i \t %i'', Tst12, Tst10, Tst8); uart_send_str(uartStr); } So there is(
DC_NUM_OF_BITS_10
> 0) defined and variableTst10
is not declared. But there is no compilation errors/ So the preprocessor derective doesnot work. Furthemore, if I declareTst10
likeuint8_t Tst12= 50, Tst10= 50, Tst8= 50;
then i get all values, passed throught uart equal to 50 The preprocessor diretives don't work. Source code inside #if ... #endif is not included for the compilating.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2015-09-30 3:21 AM
Does it work better if you nest the conditions?
Get the compiler to output the preprocessed source and see if that helps.Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2015-09-30 3:24 AM
If you printf() the values of the defines, do you see them or get an undefined error? Is the adc.h get #include'd before the use here?
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2015-09-30 4:02 AM
It does not work for nest condition too.
Just I did this test after the nest condition did not work- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2015-09-30 4:05 AM
clive1 thanks!
I was not attentive. There was not #include ''adc.h''- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2015-09-30 4:06 AM
a such stupid error. Sorry
