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

#if and #endif

What is the use of #if and #endif directives. In what way it differs from if() { }
Thanks

Parents
  • #if is processed by the preprocessor, before the compiler seens any C or C++ code.

    A normal if() is seen by the compiler and will be added to your program - the if() will be tested when the program is run.

    This means that code skipped by #if will not take any space. You can use it to create conditional builds - for example for two almost identical hardware, where one hardware have extra components mounted (and possibly an extra-large flash for the code needed to control the extra electronics).

    This is standard C knowledge, so any good book about C should give you more information.

Reply
  • #if is processed by the preprocessor, before the compiler seens any C or C++ code.

    A normal if() is seen by the compiler and will be added to your program - the if() will be tested when the program is run.

    This means that code skipped by #if will not take any space. You can use it to create conditional builds - for example for two almost identical hardware, where one hardware have extra components mounted (and possibly an extra-large flash for the code needed to control the extra electronics).

    This is standard C knowledge, so any good book about C should give you more information.

Children