I am baffled by the following behaviour of the IDE.
With the set-up below, I would expect that the IDE does, or does not, include and thus compile and link the files within the #ifdef statement, depending if #define SDB is commented out or not:
// case 1: include the .h files
#define SDB
#ifdef SDB
#include "sdb_support.h"
#include "disp_ulcd_144.h"
#include "grid_display.h"
#include "PString.h"
#include "silencer.h"
#endif
// case 2: do not include the .h files
//#define SDB
#ifdef SDB
#include "sdb_support.h"
#include "disp_ulcd_144.h"
#include "grid_display.h"
#include "PString.h"
#include "silencer.h"
#endif
And actually yes, any subsequent code is correctly dependent on the inclusions. All fine from this point of view.
Now, I would expect that the following case is equal to case 2 above, ie. commenting out the #include statements should be equal to excluding them by not defining SDB.
// case 3: do not include the .h files
//#define SDB
//#ifdef SDB
//#include "sdb_support.h"
//#include "disp_ulcd_144.h"
//#include "grid_display.h"
//#include "PString.h"
//#include "silencer.h"
//#endif
And again, all fine from a dependency point of view.
However, checking the size of the resulting code, as well as the RAM usage, I found that case 2 and case 3 are not equal. In fact, checking the verbose output of the compiler and linker shows, that in case 2 all the modules mentioned in my sketch are compiled and linked, even though I have excluded them using #ifdef. Only commenting out the #includes ensures that the not wanted files are not included in the resulting code.
I find this rather inconsistent: files don't get lexically included in my source, but their code does surprisingly get included in my executable file (*).
Do I miss something?
(*) Note that to make this test possible I don't actually use any functions from the #included files to allow successful compilations in all cases, but I have included some static vars and instantiation in the included files to see the effect in code size and RAM usage.