J
Joe C
Just learning C++...
I've recently made a leap and compiled some code I wrote with Windows in
mind for Linux. It wen't smoothly (other than having to learn about a new
compiler/os!!), However, I did have to make some changes to the code. For
example, the code needs to be aware of how filenames/paths are defined so
that it can parse filespecs and come up with new names. In the first
iteration, I just swapped out the symbols. However, As I'd prefer not to do
such work more than once, I decided to use a header ("version.h") that
contains some constants such as endianness, operating_system. THen I
extern-link to these variables and have pieces of code in the various
translation units that activate, depending on the contents of version.h.
My question...is this a fairly standard way to deal with platform-specific
issues in "portable" code, or is there an easier way? So far, I'm not using
the preprocessor to deal with this stuff.
An brief example follows...
//--version.h--
const int operating_system(0); // (0 = Win, 1 = Linux);
//--parser--
#include"version.h"
extern const int operating_system;
void parseit(){
string temp = fs;
char path_seperator('\\'); // default values...Windows
char extension_indicator('.'); // default values...Windows
extern const int operating_system;
switch(operating_system){
case 0: // Windows
path_seperator = '\\';
extension_indicator = '.';
break;
case 1: // Unix
path_seperator = '/';
extension_indicator = '.';
break;
}
// do stuff
}
Thanks, Joe
I've recently made a leap and compiled some code I wrote with Windows in
mind for Linux. It wen't smoothly (other than having to learn about a new
compiler/os!!), However, I did have to make some changes to the code. For
example, the code needs to be aware of how filenames/paths are defined so
that it can parse filespecs and come up with new names. In the first
iteration, I just swapped out the symbols. However, As I'd prefer not to do
such work more than once, I decided to use a header ("version.h") that
contains some constants such as endianness, operating_system. THen I
extern-link to these variables and have pieces of code in the various
translation units that activate, depending on the contents of version.h.
My question...is this a fairly standard way to deal with platform-specific
issues in "portable" code, or is there an easier way? So far, I'm not using
the preprocessor to deal with this stuff.
An brief example follows...
//--version.h--
const int operating_system(0); // (0 = Win, 1 = Linux);
//--parser--
#include"version.h"
extern const int operating_system;
void parseit(){
string temp = fs;
char path_seperator('\\'); // default values...Windows
char extension_indicator('.'); // default values...Windows
extern const int operating_system;
switch(operating_system){
case 0: // Windows
path_seperator = '\\';
extension_indicator = '.';
break;
case 1: // Unix
path_seperator = '/';
extension_indicator = '.';
break;
}
// do stuff
}
Thanks, Joe