2015-09-30 02: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.2015-09-30 03:21 AM
Does it work better if you nest the conditions?
Get the compiler to output the preprocessed source and see if that helps.2015-09-30 03: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?
2015-09-30 04:02 AM
It does not work for nest condition too.
Just I did this test after the nest condition did not work2015-09-30 04:05 AM
clive1 thanks!
I was not attentive. There was not #include ''adc.h''2015-09-30 04:06 AM
a such stupid error. Sorry