Skip to main content
tyr0
Associate II
September 30, 2015
Question

Keil stm32 compiler issue

  • September 30, 2015
  • 5 replies
  • 969 views
Posted on September 30, 2015 at 11:23

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.

    This topic has been closed for replies.

    5 replies

    Tesla DeLorean
    Guru
    September 30, 2015
    Posted on September 30, 2015 at 12:21

    Does it work better if you nest the conditions?

    Get the compiler to output the preprocessed source and see if that helps.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Tesla DeLorean
    Guru
    September 30, 2015
    Posted on September 30, 2015 at 12:24

    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?

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    tyr0
    tyr0Author
    Associate II
    September 30, 2015
    Posted on September 30, 2015 at 13:02

    It does not work for nest condition too.

    Just I did this test after the nest condition did not work

    tyr0
    tyr0Author
    Associate II
    September 30, 2015
    Posted on September 30, 2015 at 13:05

    clive1 thanks!

    I was not attentive. There was not #include ''adc.h''

    tyr0
    tyr0Author
    Associate II
    September 30, 2015
    Posted on September 30, 2015 at 13:06

    a such stupid error. Sorry