Conditional Compilation For Working At Home
I code C++ using MS Dev Studio and I work from home two days per week. I use CVS to keep my sources synchronized between the two computers but there are difference between the environments the machines are in.
Can anyone suggest a way I can conditionally modify constants in my code depending on whether I am compiling on my home box or not ?
What I am after is a way of defining a symbol, let's call it _ATHOME, automatically so I can do this:
#ifdef _ATHOME
# define TEST_FILES "E:\\Test"
# define TEST_SERVER "192.168.0.1"
#else
# define TEST_FILE "Z:\\Project\\Blah\\Test"
# define TEST_SERVER "212.45.68.43"
#endif
NB: This is for development and debugging purposes of course, I would never release software with hard coded constants like this.
Answer
On your home and work machines, set an environment variable LOCATION
that is either "1" for home or "2" for work.
Then in the preprocessor options, add a preprocessor define /DLOCATION=$(LOCATION). This will evaluate to either the "home" or "work" string that you set in the environment variable.
Then in your code:
#if LOCATION==1
// home
#else
// work
#endif
Related Questions
- → Comparing two large files are taking over four hours
- → Setting JSON node name to variable value
- → Compiling GLUT using Emscripten
- → Evaluate check box from a scanned image in node.js
- → Find an easy web server framework for mobile game
- → my https C++ code doesn't work on some sites (binance)
- → Error while opening pivx wallet on ubuntu
- → Why sending a POST by AJAX is interpreted by the HTTP Server as OPTIONS and sending by CURL is effectively a PUT?
- → Python reading in one line multiple types for a calculator
- → How do I properly pass an argument to a function
- → Accessing Websql database with Qt
- → Using Mysql C API for c++ codes
- → How do I set constants at run-time in a c++ header file, imported through Cython?