/* * HP-UX 9.x * cc -Aa -D_HPUX_SOURCE * HP-UX * cc -Ae * cc -Ae +DA2.0W (64) * IRIX * cc -o32 -woff 1183 * cc -n32 -mips3 -woff 1183 * cc -64 -mips3 -woff 1183 (64) * Solaris * cc -xarch=v9a (64) * cc -xarch=amd64a (64) * Tru64 * cc (64) * Linux/MacOS X * gcc -m32 * gcc -m64 (64) * * Fri Oct 17 10:34:43 CEST 2008 */ #include #include #include /* * includes for BYTE_ORDER */ #ifdef __unix # include #endif #if ( defined __sun && defined __SVR4 ) # include #elif ( defined __hpux ) # include #else # ifdef __sgi # include # endif #endif /* * end of includes for BYTE_ORDER */ #ifdef __sgi # include #endif #ifdef __STDC__ void main( void ) #else void main() #endif { char c; unsigned char uc; #ifdef __STDC__ signed char sc; #endif /* HP-UX defines __LP64__ */ #if defined(_LP64) || defined (__arch64__) || defined (__mips64) || defined (__LP64__) # define ARCH64 1 #endif #ifdef __sgi #if (_MIPS_SZPTR == 64) # define ARCH64 1 #endif #endif #if defined __alpha # define ARCH64 1 #endif #ifdef ARCH64 #define D_WORD int #else #define D_WORD long #endif static float f[]={ 0.0, -10.34, 9.99e9, 0.1e-23 }; static unsigned D_WORD l[]={0x00000000,0xC12570A4,0x5014DCD3,0x179ABE15}; union { short int s; char c[2]; } u; struct { char c; short int i; } block; u.c[0]=0x00; u.c[1]=0xaf; #ifdef ARCH64 puts("This is a 64 bits architecture"); #endif printf("size of D_WORD is %d (should be %d)\n",sizeof(D_WORD),sizeof(float)); #ifdef __STDC__ puts("__STDC__\tdefined (ANSI C compiler)"); #else puts("__STDC__\tnot defined"); #endif #ifdef __STDC_EXT__ puts("__STDC_EXT__\tdefined (ANSI C compiler + Extensions)"); #endif #ifdef LANGUAGE_C puts("LANGUAGE_C\tdefined (C)"); #endif #ifdef __cplusplus puts("__cplusplus\tdefined (C++)"); #endif #ifdef _POSIX_VERSION printf("_POSIX_VERSION\tdefined (%d)\n", _POSIX_VERSION); #endif #ifdef _XOPEN_VERSION printf("_XOPEN_VERSION\tdefined (%d)\n", _XOPEN_VERSION); #endif /******** * CPU */ /* ARM */ #ifdef __arm #define CPU_FOUND 1 puts("__arm\t\tdefined (Advanced Risc Machines ARM)"); #endif #ifdef arm #define CPU_FOUND 1 puts("arm\t\tdefined (Advanced Risc Machines ARM)"); #endif #ifdef __arm__ #define CPU_FOUND 1 puts("__arm__\t\tdefined (Advanced Risc Machines ARM)"); #endif #ifdef __arm64__ #define CPU_FOUND 1 puts("__arm64__\tdefined (Advanced Risc Machines ARM) 64 bits"); #endif /* PowerPC */ #ifdef __POWERC__ #define CPU_FOUND 1 puts("__POWERC__\tdefined (CW is generating code for the PowerPC)"); #endif #ifdef __MC68020__ #define CPU_FOUND 1 puts("__MC68020__\tdefined (CW is generating code for the 68020)"); #endif #ifdef __MC68881__ #define CPU_FOUND 1 puts("__MC68881__\tdefined (CW is generating code for the 68881)"); #endif #ifdef __ppc__ #define CPU_FOUND 1 puts("__ppc__\t\tdefined (PowerPC arch)"); #endif #ifdef __ppc64__ #define CPU_FOUND 1 puts("__ppc64__\tdefined (PowerPC 64 bits arch)"); #endif #ifdef ppc #define CPU_FOUND 1 puts("ppc\t\tdefined (PowerPC arch)"); #endif /* Intel */ #if defined (__i386) #define CPU_FOUND 1 puts("__i386\t\tdefined (x86 arch)"); #endif #if defined (i386) #define CPU_FOUND 1 puts("i386\t\tdefined (x86 arch)"); #endif #if defined(__i386__) #define CPU_FOUND 1 puts("__i386__\tdefined (x86 arch)"); #endif #if defined(M_I86) #define CPU_FOUND 1 puts("M_I86\tdefined (x86 arch)"); #endif #if defined(_M_IX86) #define CPU_FOUND 1 puts("_M_IX86\tdefined (x86 arch)"); #endif #if defined(__ia64) #define CPU_FOUND 1 puts("__ia64\tdefined (Itanium arch)"); #endif #if defined(__ia64__) #define CPU_FOUND 1 puts("__ia64__\tdefined (Itanium arch)"); #endif #if defined(__x86_64__) #define CPU_FOUND 1 puts("__x86_64__\tdefined (x86 64 bits arch)"); #endif /* Alpha */ #if defined(__alpha) #define CPU_FOUND 1 puts("__alpha\t\tdefined (Alpha)"); #endif #if defined(__arch64__) #define CPU_FOUND 1 puts("__arch64__\tdefined (Alpha, 64 bit)"); #endif /* HP PA RISC */ #if defined(__hppa) #define CPU_FOUND 1 puts("__hppa\t\tdefined (HP PA RISC)"); #if defined ( _PA_RISC1_0 ) #define CPU_FOUND 1 puts("_PA_RISC1_0\tdefined (HP PA RISC)"); #endif #if defined ( _PA_RISC1_1 ) #define CPU_FOUND 1 puts("_PA_RISC1_1\tdefined (HP PA RISC)"); #endif #if defined ( _PA_RISC2_0 ) #define CPU_FOUND 1 puts("_PA_RISC2_0\tdefined (HP PA RISC, 64 bit)"); #endif #endif /* Sparc */ #ifdef sparc #define CPU_FOUND 1 puts("__sparc\t\tdefined (SPARC arch, deprecated, use __sparc)"); #endif #ifdef __sparc #define CPU_FOUND 1 puts("__sparc\t\tdefined (SPARC arch)"); #endif #ifdef __sparcv9 #define CPU_FOUND 1 puts("__sparcv9\tdefined (SPARC V9 (64-bit) arch)"); #endif /* MIPS */ #ifdef __mips #define CPU_FOUND 1 puts("__mips\t\tdefined (MIPS arch)"); #endif #if defined (__mips64) #define CPU_FOUND 1 puts("__mips64\tdefined (MIPS arch 64 bit)"); #endif #ifndef CPU_FOUND #define CPU_FOUND 0 #endif #if ! CPU_FOUND printf("\t\t\tCPU not detected; fix source code!\n"); #endif /******** * Compiler */ #ifdef THINK_C puts("THINK_C\tdefined (Think C compiler whit Think extension active)"); #endif #if defined(__INTEL_COMPILER) puts("__INTEL_COMPILER\tdefined (Intel Compiler)"); #endif #ifdef __MWERKS__ /* ALWAYS defined for CW */ puts("__MWERKS__\tdefined (Metrowerks Code Warrior C compiler)"); #endif #ifdef __GNUC__ printf("__GNUC__\tdefined (GNU Compiler gcc %d)\n", __GNUC__); #endif #ifdef __SUNPRO_C printf("__SUNPRO_C\tdefined (Sun Compilers 0x%x)\n", __SUNPRO_C); #endif #ifdef __DECC printf("__DECC\t\tdefined (DEC Compilers)\n"); #endif #ifdef __DECC_VER printf("__DECC_VER\tdefined (DEC Compilers 0x%x)\n", __DECC_VER); #endif #ifdef _MSC_VER printf("_MSC_VER\tdefined (Microsoft Compiler %d)\n", _MSC_VER); #endif /******** * OS */ #ifdef __unix__ puts("__unix__\tdefined (Unix)"); #endif #ifdef __unix puts("__unix\t\tdefined (Unix)"); #endif #ifdef __SVR4 puts("__SVR4\t\tdefined (SYSV R4)"); #endif #ifdef _SYSTYPE_SVR4 puts("_SYSTYPE_SVR4\tdefined (SYSV R4)"); #endif #if defined __svr4__ puts("__svr4__\tdefined (SYSV R4)"); #endif #ifdef SYSTYPE_BSD puts("SYSTYPE_BSD\tdefined (BSD)"); #endif #ifdef _SYSTYPE_BSD puts("_SYSTYPE_BSD\tdefined (BSD)"); #endif #ifdef __hpux puts("__hpux\t\tdefined (HP-UX)"); #endif #ifdef _HPUX_SOURCE puts("_HPUX_SOURCE\tdefined (HP-UX source)"); #endif #if ( defined __sun__ && !defined __SVR4 ) puts("__sun__ && !__SVR4\tdefined (SunOS 4.x)"); #endif #if defined __linux__ puts("__linux__\tdefined (Linux)"); #endif #if defined __osf__ puts("__osf__\t\tdefined (Tru64/OSF)"); #endif #if defined __convexc__ puts("__convexc__\tdefined (cc on Convex)"); #endif #if defined WIN32 puts("WIN32\tdefined (Windows 95/98/NT/2000/XP)"); #endif /******** * Hardware */ #ifdef __APPLE__ puts("__APPLE__\tdefined (Apple)"); #endif /* http://developer.apple.com/technotes/tn2002/tn2071.html */ #if defined(__MACH__) && defined(__APPLE__) puts("__MACH__ && __APPLE__\tdefined (Probably gcc/pb in MacOS X)"); #endif #if defined(macintosh) puts("macintosh\tdefined (Macintosh, MacOS 9.x or earlier)"); #endif #if defined(__MACOS__) puts("__MACOS__\tdefined (MacOS, Probably MacOS 9.x or earlier)"); #endif #ifdef __sun puts("__sun\t\tdefined (Sun Microsystems)"); #endif #ifdef __sun__ puts("__sun__\t\tdefined (Sun Microsystems)"); #endif #ifdef __sgi puts("__sgi\t\tdefined (SGI)\n"); { char buf[8]; sysinfo(_MIPS_SI_OS_NAME, buf, 7); if (strcmp("IRIX",buf) == 0) { puts("IRIX OS"); } else if (strcmp("IRIX64",buf) == 0) { puts("IRIX64 OS"); } else { puts("Unknown SGI OS"); } } #endif printf("\nchar:\t\t%d\n", (int)sizeof(char)); printf("short:\t\t%d\n", (int)sizeof(short)); printf("int:\t\t%d\n", (int)sizeof(int)); printf("long:\t\t%d\n", (int)sizeof(long)); printf("float:\t\t%d\n", (int)sizeof(float)); printf("double:\t\t%d\n", (int)sizeof(double)); printf("size_t:\t\t%d\n", (int)sizeof(size_t)); printf("void *:\t\t%d\n", (int)sizeof(void *)); #ifndef ARCH64 if ( sizeof (void *) == 8 ) printf("\t\t\t64 bit architecture, not detected; fix source code!\n"); #endif #ifdef __STDC__ printf("long double:\t%d\t", (int)sizeof(long double)); puts("Warning: long double is an ANSI feature"); #if defined(__hpux) # if !defined (_POSIX_VERSION) printf("long long:\t%s\t", "Not supported on this HP-UX/cc release/cflags"); # elif defined(__hppa) printf("long long:\t%d\t", (int)sizeof(long long)); # endif #else printf("long long:\t%d\t", (int)sizeof(long long)); puts("Warning: long long is an ANSI feature"); #endif #endif block.c = 'a'; block.i = 1; printf("\nsizeof(char+short)=%d\n", (int)sizeof(block)); printf("sizeof(char)+sizeof(short)=%d\n\n", (int)sizeof(char)+(int)sizeof(short)); c=0xaf; uc=0xaf; if (c<0) puts("char is signed"); else puts("char is unsigned"); if (uc<0) puts("unsigned char is signed"); else puts("unsigned char is unsigned"); #ifdef __STDC__ sc=0xaf; if (sc<0) printf("signed char is signed\t"); else printf("signed char is unsigned\t"); puts("Warning: signed char is an ANSI feature"); #endif puts("\nfloat IEEE:"); printf("%.8X\t%.8X\n%X\t%X\n%X\t%X\n%X\t%X\n\n", *(unsigned D_WORD*)&f[0], l[0], *(unsigned D_WORD*)&f[1], l[1], *(unsigned D_WORD*)&f[2], l[2], *(unsigned D_WORD*)&f[3], l[3] ); fflush(stdout); /* Linux, Mac OS X, maybe gcc generic? */ #ifdef BYTE_ORDER printf("BYTE_ORDER defined (%d)\n",BYTE_ORDER); # if ( BYTE_ORDER == BIG_ENDIAN ) printf("BYTE_ORDER is BIG_ENDIAN\n"); # define HOST_IS_LITTLE_ENDIAN 0 # elif ( BYTE_ORDER == LITTLE_ENDIAN ) printf("BYTE_ORDER is LITTLE_ENDIAN\n"); # define HOST_IS_LITTLE_ENDIAN 1 # elif ( BYTE_ORDER == PDP_ENDIAN ) printf("BYTE_ORDER is PDP_ENDIAN\n"); # define HOST_IS_LITTLE_ENDIAN 0 # endif #else /* Intel, Alpha */ # if defined(__i386__) || defined (M_I86) || defined (_M_IX86) ||\ defined (WIN32) # define HOST_IS_LITTLE_ENDIAN 1 # else /* I don't remember which one defines this: */ # ifdef __BIG_ENDIAN__ printf("__BIG_ENDIAN__ defined\n"); # define HOST_IS_LITTLE_ENDIAN 0 # endif # endif #endif #ifndef __sgi #ifdef _LITTLE_ENDIAN printf("_LITTLE_ENDIAN defined\n"); # ifndef HOST_IS_LITTLE_ENDIAN # define HOST_IS_LITTLE_ENDIAN 1 # endif #endif #ifdef _BIG_ENDIAN printf("_BIG_ENDIAN defined\n"); # ifndef HOST_IS_LITTLE_ENDIAN # define HOST_IS_LITTLE_ENDIAN 0 # endif #endif #endif /* MIPS SGI IRIX */ #ifdef _MIPSEB printf("_MIPSEB defined (IRIX MIPS big endian)\n"); # define MIPS_IS_LITTLE_ENDIAN 0 #endif #ifdef _MIPSEL printf("_MIPSEL defined (IRIX MIPS little endian)\n"); # define MIPS_IS_LITTLE_ENDIAN 1 #endif #ifdef MIPS_IS_LITTLE_ENDIAN #if ( MIPS_IS_LITTLE_ENDIAN != HOST_IS_LITTLE_ENDIAN ) printf("WARNING: MIPS != HOST endianess\n"); #endif #endif #ifndef HOST_IS_LITTLE_ENDIAN /* default to big endian */ # define HOST_IS_LITTLE_ENDIAN 0 #endif if ( u.s == 175 ) { puts("big-endian (MC680*0)"); #if HOST_IS_LITTLE_ENDIAN printf("\t\t\tbig endian, not detected; fix source code!\n"); #endif } else { #if ! HOST_IS_LITTLE_ENDIAN printf("\t\t\tlittle endian, not detected; fix source code!\n"); #endif puts("little-endian (80*86)"); } }