AnsweredAssumed Answered

Keil stm32 compiler issue

Question asked by a.alya on Sep 30, 2015
Latest reply on Sep 30, 2015 by a.alya
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 variable Tst10 is not declared.
But there is no compilation errors/
So the preprocessor derective doesnot work.
Furthemore, if I declare Tst10 like
uint8_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.

Outcomes