Date: Tue, 22 Apr 1997 11:32:07 +0800 (GMT) From: Orlando Andico To: Andrew Deren cc: djgpp Subject: Re: dos/unix defines In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Precedence: bulk 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.."