delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/04/21/23:54:51

Date: Tue, 22 Apr 1997 11:32:07 +0800 (GMT)
From: Orlando Andico <orly AT gibson DOT eee DOT upd DOT edu DOT ph>
To: Andrew Deren <aderen AT eecs DOT uic DOT edu>
cc: djgpp <djgpp AT delorie DOT com>
Subject: Re: dos/unix defines
In-Reply-To: <Pine.SUN.3.95.970421155639.26004A-100000@bert.eecs.uic.edu>
Message-ID: <Pine.SGI.3.93.970422112220.7282C-100000@gibson.eee.upd.edu.ph>
MIME-Version: 1.0

On Mon, 21 Apr 1997, Andrew Deren wrote:

> Does anyone know what #define I have to use to detect whether a program is
> compiled on DOS or UNIX. I use Borland C++ and DJGPP for DOS and gcc and
> CC for unix if that matters.
> THanks.
> 

Depends on your UNIX version and C compiler. __unix__ is defined by all
the GCC's I've seen, even DJGPP, so that's not a smart one. I personally
use the following (n.b. _all_ the #defines I use are made by GCC, so this 
code will only be reliable on GCC machines; besides, I've only tested
this code on DJGPP under DOS, DJGPP under Linux, Linux-ELF 1.x and 2.x,
Solaris 2.x, SunOS 4.x (both SPARC), and IRIX 5.3):

#ifdef __sgi
#ifdef __SVR4_SOURCE
 printf ("running on SGI IRIX 5.x/6.x\n");
#else
 printf ("running on SGI IRIX 4.x\n");
#endif
#endif

#ifdef __linux__
 printf ("running on Linux\n");
#endif

#ifdef __sun__
#ifdef __sparc__
 printf ("running on Sun SPARC.. ");
#else
 printf ("running on Sun non-SPARC.. ");
#endif

#ifdef __svr4__
 printf ("under Solaris 2.x\n");
#else
 printf ("under SunOS 4.x or lower\n");
#endif

#ifdef __MSDOS__
 printf ("running under MSDOS.. ");
#ifdef __DJGPP__
 printf ("under DJGPP\n");
#else
 printf ("under non-GNU compiler\n");
#endif
#endif



-----------------------------------------------------------------------
Orlando Andico                               IRC Lab/EE Dept/UP Diliman
email: orly AT gibson DOT eee DOT upd DOT edu DOT ph          http://gibson.eee.upd.edu.ph
   "There's an obvious attraction to the path of least resistance.."

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019