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
  • I could be missing something, but what is the point of defining __MAIN_H in your code sample? Normally it's done to avoid multiple inclusion. But in order to achieve this you have to move the #endif from line 3 to the last line of your header file.

Reply
  • I could be missing something, but what is the point of defining __MAIN_H in your code sample? Normally it's done to avoid multiple inclusion. But in order to achieve this you have to move the #endif from line 3 to the last line of your header file.

Children
  • I assumed that he had something inserted there, but now removed for brevity.

    Anyway - most source code editors don't look for keywords in preprcessor lines - as soon as they see #define they color the full line using the "preprocessor" color. Same thing with comments - try to write keywords inside comments, and you still get the markup for a comment.