From: MARSHALL Keith <Keith.MARSHALL@total.com> - 2004-05-18 15:20:12
John Dill wrote:
> Try this sample.
> int main( int argc, char **argv )
> #if (PLATFORM == linux)
> std::cout << "Linux..." << std::endl;
> #elif (PLATFORM == mingw)
> std::cout << "MinGW..." << std::endl;
> std::cout << "Unknown..." << std::endl;
> return 0;
Try adding ...
#define linux 1
#define mingw 2
above your main() function.
When you do comparisons with #if like this, the entities
either side of == are considered as symbols representing
integer values. Any symbol which isn't defined is implicitly
assumed to be zero, so, if you define PLATFORM=linux, and
don't define linux to be non-zero, PLATFORM == linux
resolves as 0 == 0, which is always true!
Having said this, however, for platform dependent issues,
you are much better relying on standard definitions such as
_WIN32 for 32-bit Windows, __CYGWIN__ and __MINGW32__ for
the obvious. I am not aware of any such symbol specific to
Linux, but Linux compliant code should also be compatible
with other UNIX systems; just make your default platform
UNIX (POSIX) compatible. There *are* predefined symbols to
resolve differing levels of POSIX compliance on such systems,
and also some architecture dependent symbols, for non-PC
Have a look at http://www.gnu.org/software/gcc/onlinedocs,
for the authoritative reference.
Get latest updates about Open Source Projects, Conferences and News.