I have to make conditional compilation to skip some part of code when they are not being used. The project is a MCU project which consists of external modules like LEDs, LCD, Keypads etc.
I have a optimization.h
file which is used to tell which modules are used at the time of compilation. It goes like this...
#ifndef OPTIMIZATION_H
#define OPTIMIZATION_H
// 1 - Compile code only for given modules
// 0 - Compile for all available modules
#define _OPTIMIZE_ 1
// Modules to compile
#define _LED_ 1
#define _SWITCH_ 1
// Modules not to compile
#define _LCD_ 0
#define _SSD_ 0
#endif
The code.c
file goes like this...
#include "optimization.h"
void myFun()
{
// Compile when LED is used or all modules are asked to use
// i.e when _OPTIMIZE_ is 0 or _LED_ is 1
// Need to compile this code
#if !(_OPTIMIZE_) || (_LED_)
/* My code goes here */
#endif
// Need to compile this code
#if !(_OPTIMIZE_) || (_SWITCH_)
/* My code goes here */
#endif
// Need not to compile
#if !(_OPTIMIZE_) || (_LCD_)
/* My code goes here */
#endif
// Need not to compile
#if !(_OPTIMIZE_) || (_SSD_)
/* My code goes here */
#endif
}
If I wanted to use only LED and SWITCH only that part of code should be compiled. But all modules are compiled every time. What may be the problem...