Which compiler is this?

From: Bob Crispen (bob.crispen_at_boeing.com)
Date: 18 March 2003


Found this news:Xns9342609104B39revbob_at_192.54.3.19 in boeing.comp.misc:

-= BEGIN forwarded message =-

Subject: Which compiler is this?
From: Bob Crispen <bob.crispen_at_boeing.com> Newsgroups: boeing.comp.misc
Organization: Modeling & Simulation Technology, Phantom Works, Boeing

Thanks to Joe Meadows, here's the latest. You can save it as whatever.c and determine what compiler is compiling it. Happy, happy, joy, joy. On ---x systems it doesn't matter so much, but Windows systems tend to stick some of their prototypes in strange places, so it's kinda useful to say

#ifndef __GNUC__
#include <string.h> // memcpy() is a builtin in gcc
#endif

The only one that's a little dicey is __MINGW32__. I *think* Mumit Khan has folded all of his mingw32 distribution into the gcc database, but I decided a while back that I didn't want to follow those events. So it definitely designates Cygwin gcc with the -mno-cygwin flag set, but there's a small probability that it designates another mingw32 distribution as well.

Anybody got any other compiler-specific symbols?

/*
 * what_compiler.c
 *
 * These are the flags a C program can use to determine what compiler
 * is compiling it so it can manage compiler-specific quirks.
 *
 * Presented this way just so you can see with your own eyeballs that
 * these are reasonable symbols to use.
 *
 * Probably isn't much good except to identify C compilers for Windows.
 */

#include <stdio.h>

int main()
{

// Microsoft Visual C++
//

    printf("_MSC_VER : ");
#if defined (_MSC_VER)

    printf("yes\n");
#else

    printf("no\n");
#endif

// Jacob Navia's LCC-Win32
//

    printf("__LCC__ : ");
#if defined(__LCC__)

    printf("yes\n");
#else

    printf("no\n");
#endif

// gcc (confirmed for Cygwin and SPARC/Solaris) //

    printf("__GNUC__ : ");
#if defined(__GNUC__)

    printf("yes\n");
#else

    printf("no\n");
#endif

// Cygwin, *not* compiled -mno-cygwin
//

    printf("__CYGWIN32__ : ");
#if defined(__CYGWIN32__)

    printf("yes\n");
#else

    printf("no\n");
#endif

// Cygwin, compiled -mno-cygwin
//

    printf("__MINGW32__ : ");
#if defined(__MINGW32__)

    printf("yes\n");
#else

    printf("no\n");
#endif

    return 0;
}

-- 
Bob Crispen
bob.crispen_at_boeing.com
That which does not kill us has made its last mistake.
-= END forwarded message =-


This archive was generated by hypermail pre-2.1.8 : 26 April 2003 EDT