Question

I have two C files, one called main.c the other batterysaver.c. Instead of including the code that I have in batterysaver.c into the main.c file, and using a conditional compile, I want to have two separate files, but be able to set which file is compiled given a preprocessor directive. Is this possible?

This is the main.c file's header:

//standard header
#include "pebble.h"
#include "iota.h"
#define BATTERY false

//app-specific data
Window *window; //obvious window is obvious
TextLayer *time_layer; //time layer

#if !BATTERY
*REST OF FILE STARTS HERE, THEN AT THE END*
#endif

This is the batterysaver.c file's header:

#include "main.c"

#if BATTERY
*REST OF FILE STARTS HERE, THEN AT THE END*
#endif

I appreciate any and all help.

Was it helpful?

Solution

Including a .cc file in another .cc file is indicative of unclean design.

You can conditionally compile in/out portions of the code in main.cc and batterysaver.cc based on whether BATTERY has been defined or not.

If that doesn't work, you have to ask yourself how you can put common declarations in a .h file and include the .h file in both the .cc files.

my_common.h

#ifndef MY_COMMON_H
#define MY_COMMON_H

//standard header
#include "pebble.h"
#include "iota.h"
#define BATTERY false

//app-specific data
extern Window *window; //obvious window is obvious
extern TextLayer *time_layer; //time layer

#ENDIF

main.cc

#include "my_common.h"

Window *window; //obvious window is obvious
TextLayer *time_layer; //time layer

#if !BATTERY
*REST OF FILE STARTS HERE, THEN AT THE END*
#endif

battarysaver.cc

#include "my_common.h"

#if BATTERY
*REST OF FILE STARTS HERE, THEN AT THE END*
#endif
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top