This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Preprocessor directives

Hello together,

I'm coding a simple UART-Application on the MCBSTM32 eval board and have problems with the preprocessor directives. I studied the whole documentation here and I'm pretty sure I'm coding in a common way, but still I can't compile my program. These are the very first lines of my main header file:

#ifndef ___MAIN_H_
#define ___MAIN_H_
#endif

#undef EX

#ifndef ___MAIN_C_
  #define EX extern
#else
  #define EX
#endif

And my variables a coded that way:

EX unsigned int ui_TxFrameCounter;

When compiling the program, I get the error code "L6200E: symbol multiply defined" for my variables, because of including the header to other files. I want to declare the variables "extern" for the other header files. Could somebody help me? Would be nice.
Geetings

Parents
  • Thanks for your comments!
    So what would you prefer? How would you solve the problem with the global variables?

    I'm tryin it at the moment with this code in main.h:

    #define MAIN_H_
    
    #undef EX
    
    #ifndef MAIN_C_
      #define EX extern
    #else
      #define EX
    
    //Prototypes and variable declarations...
    //...
    
    #endif //at the end of file
    


    But this doesn't work too. I still need to declarate the variables in the main.c , otherwise they are not known.
    Greetings

Reply
  • Thanks for your comments!
    So what would you prefer? How would you solve the problem with the global variables?

    I'm tryin it at the moment with this code in main.h:

    #define MAIN_H_
    
    #undef EX
    
    #ifndef MAIN_C_
      #define EX extern
    #else
      #define EX
    
    //Prototypes and variable declarations...
    //...
    
    #endif //at the end of file
    


    But this doesn't work too. I still need to declarate the variables in the main.c , otherwise they are not known.
    Greetings

Children