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

Conditional Compiling for a library

in referrence to following code, while generating library, what code would be included? My handler code or user callback function call???

void IRQ_Handler(void)
{
#if MACRO_ENABLED

  // My handler code

#elif

  // User handler callback function

#endif
}

how should i write my code so that both sections are included in the library and the library user gets the power to chose what part he wants to be executed?
i could come up with following solution.


#define MACRO_ENABLED

ExecuteFlg = MACRO_ENABLED


void IRQ_Handler(void)
{
  if(ExecuteFlg)
  {
    // My handler code
  }
  else if
  {
    // User handler callback function
  }

}

is there any other way to achieve this???

Parents
  • A library is something that is precompiled.

    Precompiled means all compilation decisions was made before the library output file was generated - the project making use of the library will merge in the library functionality at link time.

    So #define, #ifdef etc used inside the library C/C++ files will not work to control functionality.

    But compiling in both alternatives into the library, you could have the user of the library either supply a parameter when calling a function/method, or setting a global variable. And it is possible to make use of a #define to control what value that global variable should get as long as that assign happens outside the library and instead happens when the library user compiles their own source code.

Reply
  • A library is something that is precompiled.

    Precompiled means all compilation decisions was made before the library output file was generated - the project making use of the library will merge in the library functionality at link time.

    So #define, #ifdef etc used inside the library C/C++ files will not work to control functionality.

    But compiling in both alternatives into the library, you could have the user of the library either supply a parameter when calling a function/method, or setting a global variable. And it is possible to make use of a #define to control what value that global variable should get as long as that assign happens outside the library and instead happens when the library user compiles their own source code.

Children