473,378 Members | 1,309 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

environment variable


hi all,
i'd like to write a cross platform c++ code (on linux and windows); between
the tow codes there are just small differences; is there a macro or
variable that could let me at the compile time discover on which platform
my code is running?
thanks
Jul 19 '05 #1
3 5131

"fabio" <th*********@yahoo.com> wrote in message news:3f60571c@shknews01...

hi all,
i'd like to write a cross platform c++ code (on linux and windows); between the tow codes there are just small differences; is there a macro or
variable that could let me at the compile time discover on which platform
my code is running?
thanks


You'll need to compile the code on separate platforms, right? So, just
create your own #define and wrap the platform-specific code in #ifdef's
using the symbol you defined. No need to check at run-time.

-Howard

Jul 19 '05 #2
Use #ifdef construction in in your code.
Define WIN32 variable in your make file if you compile executable for
Win32 and udefine it otherwise

#ifdef WIN32
// code specific for Win32 platform
...
#else
// code specific for Linux platform
...
#endif

Regards,
Vlad.

Jul 19 '05 #3
WW
vl****************@ams.com wrote:
Use #ifdef construction in in your code.
Define WIN32 variable in your make file if you compile executable for
Win32 and udefine it otherwise

#ifdef WIN32
// code specific for Win32 platform
...
#else
// code specific for Linux platform
...
#endif


Please do not post HTML here, this is a text only newsgroup. So many will
not be able to read your posts.

Also please note that in C++ it is highly discouraged to fill your code with
ifdefs. The suggested approach is to factor out the platform dependent part
into separate classes (or into separate inline functions if speed matters)
and make the build environment pick up the right implementation.

--
WW aka Attila
Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

28
by: Christian | last post by:
Another question from a not even newbie: In Unix you can set an environment variable with the command export PYTHONPATH but I would like to set the variable from at .py script. So my question...
13
by: Jimmy Cracker | last post by:
Is it completely impossible in UNIX to push an environment variable to the parent shell? I would like to do something like this: main(int argc, char *argv) { char *var; var = (char...
1
by: Bonj | last post by:
Hi My application installs a front-end GUI, which runs code when buttons are clicked. It also installs a command-line utility, that is a console application. They are both installed to the...
4
by: | last post by:
Hi all, I am trying to append a certain string to the PATH environment variable programmatically. I am able to read what is in the variable using the System.Environment method...
3
by: Strauss | last post by:
Hi: I'm setting the INCLUDE environment variable, but VC is not searching it for header files (I've checked it with filemon). I've tried with user variable, machine variable, rebooted the...
6
by: yaron | last post by:
Hi, my application use environment variable, let call it FOO. how can i add the FOO environment variable to my project or my solution, so the line string foo =...
0
by: Joe HM | last post by:
Hello - I am putting together a little ConsoleApplication that is supposed to check for an Environment Variable and create it if it does not exist. I found some code that will add a new...
0
by: mirandacascade | last post by:
Apologies in advance for what I'm guessing may be a trivial question. Assume the following: 1) multi-user environment 2) standard (i.e. not a class module) module with: Public strSample as...
4
by: Stephen Cattaneo | last post by:
Hello all, I am attempting to execute an automated test (written in Python) via cron. I have to check the HOSTNAME variable as part of the test, oddly under cron the HOSTNAME environment...
4
by: vkbishnoi | last post by:
I need to create an environment variable for another local user in windows. For example, say suppose there are 2 users in the system (User1 and User2). Currently User1 is logged in the system. Now Is...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.