environment variable

F

fabio

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
 
H

Howard

fabio said:
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
 
V

vladimir.druzdenko

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.
 
W

WW

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,142
Messages
2,570,819
Members
47,367
Latest member
mahdiharooniir

Latest Threads

Top