Main /

Platform Independent Programming

Wiki_System*

technolowiki.org

[-edit SideBar-]

Platform Independent Programming

Platform Independent Programming

well, it is likely that you will never see a completely platform-independent programming language or framework. It seems Java is the only one that comes close to it. But you can satisfy some platforms having a similar architecture through the use of precompiler statements / conditional blocks. These are:

Platform / Architecture switches

\#ifdef __alpha__ \#ifdef __alpha_ev4__ // Alpha EV4 CPU \#ifdef __alpha_ev5__ // Alpha EV5 CPU \#ifdef __alpha_ev6__ // Alpha EV6 CPU \#ifdef __amd64 // AMD64 CPU in GNU and Sun compilers \#ifdef __amd64__ \#ifdef __APPLE__ \#ifdef _ARM // ARM CPU in ImageCraft C \#ifdef __arm__ // ARM CPU in GNU and RealView \#ifdef i386 // intel 386 or newer in GNU compilers \#ifdef __i386 // intel 386 or newer in Sun Studio \#ifdef __i386__ // intel 386 or newer in GNU compilers \#ifdef __i486__ // intel 486 or newer in GNU compilers \#ifdef __i586__ // intel pentium or newer in GNU compilers \#ifdef __i686__ // intel ??? or newer in GNU compilers \#ifdef _IA64 // intel 64-bit CPU in GNU C \#ifdef __IA64__ \#ifdef __ia64__ \#ifdef __INTEL__ // intel x86 in CodeWarrior \#ifdef __m68k__ // motorola 680x0 in GNU C, can be 68000, 68010, 68020, 68030, 68040, 68060 \#ifdef _M_ALPHA // DEC alpha target in Visual Studio (deprecated as alpha is no longer supported by microsoft) \#ifdef _M_IA64 // intel 64-bit CPU in Visual Studio and intel C/C++ (=64100) \#ifdef _M_IX86 // 300, for i386 - 400, for i486 - 500, for Pentium - 600, for Pentium Pro/II - in Visual Studio, intel C/C++, Digital Mars and Watcom \#ifdef _M_IX86_FP // floating-point/multimedia instruction support: 0, for none - 1, for SSE - 2, for SSE2 \#ifdef _M_PPC // 601, for PowerPC 601 - 603, for 603 - 604, for 604 - 620, for 620 in Visual Studio \#ifdef _M_X64 // AMD64 CPU in Visual Studio \#ifdef mips // 1, for R2000 and R3000 MIPS CPU - 2, for R6000 - 3, for R4400 - 4, for R8000 and R10000 in GNU C \#ifdef __mips__ \#ifdef __NEXT_RUNTIME__ // NeXT runtime in Objective-C \#if PLATFORM == PC \#if PLATFORM == XBOX360 \#ifdef __powerpc // set, for PowerPC in GNU C \#ifdef __powerpc__ \#ifdef __POWERPC__ \#ifdef __ppc__ \#ifdef _R3000 // set, for MIPS R3000 \#ifdef _R4000 // set, for MIPS R4000 \#ifdef __sparc // set, for SPARC in Sun Studio \#ifdef __sparc__ // set, for SPARC in GNU C \#ifdef __sparcv8 // set, for SuperSPARC \#ifdef __sparcv9 // set, for UltraSPARC \#ifdef __thumb__ // ARM CPU (thumb mode) in GNU and RealView \#ifdef _X86_ // intel x86 in MinGW32 \#ifdef __X86__ // intel x86 in Watcom \#ifdef __x86_64__ // AMD64 CPU in GNU and Sun compilers \#ifdef __x86_64

Hardware Property switches

\#if __CHAR_BIT__==8 __INT_MAX__ // max value for type int _INTEGRAL_MAX_BITS // set to the maximum size, in bits, for an integral type __LONG_MAX__ // max value for type long __LONG_LONG_MAX__ // max value for type long long \#ifdef _LP64 // 1, if target has 64-bit pointers and long ints, but 32-bit ints \#ifdef __LP64__ __PTRDIFF_TYPE__ // use ptrdiff_t instead \#ifdef __REGISTER_PREFIX__ __SCHAR_MAX__ // max value for type char __SHRT_MAX__ // max value for type short __SIZE_TYPE__ // use size_t instead \#ifdef __USER_LABEL_PREFIX__ \#ifdef __USING_SJLJ_EXCEPTIONS__ // 1, if the compiler uses old setjmp/longjmp mechanism for exception handling __WCHAR_MAX__ // max value for type wchar __WCHAR_TYPE__ // use wchar_t instead __WINT_TYPE__ // use wint_t instead

Operating System, Framework and Library switches

(framework macros may require <features.h> included, operating system macros may require <osreldate.h> included.)
\#ifdef _AIX // set for AIX \#ifdef _AIX3 // set for AIX 3 and newer \#ifdef _AIX32 // set for AIX 3.2 and newer \#ifdef _AIX41 // set for AIX 4.1 and newer \#ifdef _AIX43 // set for AIX 4.3 and newer \#ifdef AMIGA \#ifdef __amigaos__ // set, for AmigaOS in GNU C \#ifdef __APPLE__ // set, for Apple Systems \#ifdef _ATL_VER // version of Microsoft Active Template Library \#ifdef _BEOS_ \#ifdef __BEOS__ \#ifdef BSD \#ifdef __CLR_VER // version of Microsoft Common Language Runtime (.net), like "Mmmbbbbb" \#ifdef __CPPLIB_VER // Dinkumware C++ lib \#ifdef __cplusplus_cli // set to 200406 if CLR for C++ is present _CPPLIB_VER // version of the C++ standard library ("Dinkumware") \#ifdef __CRTL_VER // VMS libc \#ifdef __DOS__ \#ifdef __ELF__ \#ifdef __FreeBSD__ // 1, for FreeBSD 1.x - 2, for 2.x - 3, for 3.0 - 4, for 4.x __FreeBSD_version // 119411, for FreeBSD 2.0 - 220000 for 2.2 - 300005 for 3.0 - 400017, for 4.0 - 450000, for 4.5 \#ifdef __GNU_LIBRARY__ // GNU glibc until 5.0 \#ifdef __GNU_LIBRARY_MINOR__ \#ifdef __GLIBC__ // GNU glibc 6.0 and newer \#ifdef __GLIBC_MINOR__ \#ifdef __GLIBCPP__ // GNU libstdc++ 3.0 until 3.3 \#ifdef __GLIBCXX__ // GNU libstdc++ 3.4 and newer \#ifdef hpux \#ifdef _hpux // for HP-UX in GNU C \#ifdef __hpux \#ifdef __INTEL_CXXLIB_ICC // Intel C++ runtime library \#ifdef __LIBREL__ // IBM z/OS libc \#ifdef linux \#ifdef __linux \#ifdef __linux__ \#ifdef M_XENIX // set, for SCO OpenServer in GNU C \#ifdef __MACH__ // set, for Mac OS X (if __APPLE__ is also set) \#ifdef macintosh // set, for Mac OS 9 \#ifdef Macintosh \#ifdef __MACOSX__ \#ifdef _MFC_VER // Microsoft Foundation Classes framework \#ifdef _mips \#ifdef __mips__ \#ifdef MSDOS \#ifdef _MSDOS \#ifdef __MSDOS__ \#ifdef __NetBSD__ \#ifdef __NetBSD0_8 // set, for NetBSD 0.8 \#ifdef __NetBSD0_9 // set, for NetBSD 0.9 \#ifdef __NetBSD1_0 // 1, for NetBSD 1.0 - 2, for 1.0a __NetBSD_Version[__] // 102040000, for 1.2d - 102000100, for 1.2.1 \#ifdef __OpenBSD__ \#ifdef OpenBSD3_1 \#ifdef OpenBSD3_9 \#ifdef OS2 \#ifdef _OS2 \#ifdef __OS2__ \#ifdef __TOS_OS2__ _POSIX_VERSION // "198808L", for POSIX.1-1988 - "199009L", for POSIX.1-1990 - "199309L", for POSIX.1b-1993 - "199506L", for POSIX.1-1996 - "200112L", for POSIX.1-2001 _POSIX2_C_VERSION // "199209L", for POSIX.2 \#ifdef __QNX__ \#ifdef __QNXNTO__ \#ifdef _NTO_VERSION // 620, for 6.2 \#ifdef _SCO_DS // SCO OpenServer \#ifdef sgi // set, for IRIX \#ifdef __sgi \#ifdef __TARGET_LIB__ // IBM z/OS libc \#ifdef __UCLIBC__ // uClibc \#ifdef __UCLIBC_MAJOR__ \#ifdef __UCLIBC_MINOR__ \#ifdef __UCLIBC_SUBLEVEL__ \#ifdef unix \#ifdef __unix__ \#ifdef __VMS_VER \#ifdef _WINDOWS \#ifdef WIN32 \#ifdef _WIN32 \#ifdef WIN32_PLATFORM_HPC2000 // set, for H/PC 2000 \#ifdef WIN32_PLATFORM_HPCPRO // 211, for H/PC Pro 2.11 - 300 for H/PC Pro 3.0 \#ifdef WIN32_PLATFORM_PSPC // 1, for Pocket PC - 310, for Pocket PC 2002 - 400, for Windows Mobile 2003 \#ifdef WIN32_PLATFORM_WFSP // 100, for Smartphone 2002 \#ifdef _WIN32_WCE // 201, for Windows CE 2.01 - 211 for 2.11 - 300, for 3.0 - 400, for 4.0 - 410, for 4.1 - 420, for 4.2 - 501, for 5.0 \#ifdef _WIN64 \#ifdef __WINDOWS__ // set, for Windows Systems in Watcom \#ifdef _XOPEN_UNIX \#ifdef _XOPEN_VERSION // 3, for XPG3/1989 - 4, for XPG4/1992 - 500, for SUSv2/1998 - 600, for SUSv3/2003

Compiler Environment switches

(unix standards macros require <unistd.h> included.)
\#ifdef __BORLANDC__ // 512, for Borland C++ 2.0 - 1024, for 3.0 - 1040, for 3.1 - 1106, for 4.0 - 1280, for 5.0 - 1312, for 5.02 (Builder 1.0) - 1328, for Builder 3.0 - 1344, for Builder 4.0 - 1360, for 5.5 (Builder 5.0) - 1361, for 5.51 \#ifdef __C166__ // Keil C166 \#ifdef __C51__ // Keil C51 \#ifdef __CX51__ // Keil C51 \#ifdef __CA__ // Keil version \#ifdef __cplusplus // "199707L", for C++ 98 \#ifdef __cplusplus_cli // "200406L", for C++/CLI \#ifdef _CPPRTTI // set, if compiling with support for run-time type information \#ifdef _CPPUNWIND // set, if compiling with enabled exception-handling \#ifdef __CYGWIN__ \#ifdef _DEBUG // set, if compiling with debug/symbolic information \#ifdef _DLL // set, if building for windows DLL target __ECC // obsolete, use __INTEL_COMPILER \#ifdef __embedded_cplusplus // 1, for EC++ __FUNCDNAME__ // within functions, returns the fully decorated name of this function __FUNCSIG__ // within functions, returns the signature/calling method, for example "__cdecl" __FUNCTION__ // within functions, returns the undecorated name of this function \#ifdef __GNUC__ // this is a gnu C compiler, major version number specified \#ifdef __GNUC_MINOR__ // minor version number of gnu compiler \#ifdef __GNUC_PATCHLEVEL__ // subminor version number, or '.' \#ifdef __GNUG__ // this is a gnu C++ compiler __ICC // obsolete, use __INTEL_COMPILER __ICL // same as __INTEL_COMPILER \#ifdef __INTEL_COMPILER // 1105, for 11.0.5 \#ifdef __INTEL_COMPILER_BUILD_DATE // available in 9.0 and newer, like 'YYYYMMDD' \#ifdef __KEIL__ // Keil CARM \#if _MAJOR_REV > 1 // Ultimate C/C++ \#if _MINOR_REV > 0 // Ultimate C/C++ \#ifdef __MINGW32__ \#ifdef __MINGW32_MAJOR_VERSION \#ifdef __MINGW32_MINOR_VERSION \#ifdef _MSC_EXTENSIONS \#ifdef _MSC_VER // 800, for Visual C++ 1.0 - 900, for 3.0 - 1000, for 4.0 - 1020, for 4.2 - 1100, for 5.0 - 1200, for 6.0 - 1300, for 7.0 - 1310, for 7.1 (Studio 2003) - 1400, for 8.0 (Studio 2005) - 1500, for 9.0 (Studio 2008) _MSC_FULL_VER // 12008804, for 6.0 SP6 - 13009466, for 7.0 - 13103077, for 7.1 - 140050727, for 8.0 (note the length increase) - 150020706, for 9.0 \#ifdef __MWERKS__ // Metrowerks CodeWarrior \#ifdef _PACC_VER // Palm C/C++ \#ifdef __OBJC__ \#ifdef SDCC // Small Device C Compiler \#ifdef __STRICT_ANSI__ \#ifdef __SUNPRO_C // Sun Studio C \#ifdef __SUNPRO_CC // Sun Studio C++ \#ifdef __TINYC__ \#ifdef __TURBOC__ // 397, for Borland Turbo C 2.0 - 661, for 3.0 \#ifdef _UCC // Ultimate C/C++ \#ifdef __VERSION__ // compiler version \#ifdef __WATCOMC__ // 1050, for Watcom C++ 10.5 - 1100, for 11.0 - 1200, for Open Watcom C++ 1.0 - 1270, for 1.7for even more compilers, see the Predef Sourceforge Project.

Optimization, Target and unverified switches

\#ifdef USERMODE_DRIVER \#ifdef APPLE_HYB \#ifdef __CHAR_UNSIGNED \#ifdef __CHAR_UNSIGNED__ \#ifdef __EMX__ \#ifdef IS_CYGWIN \#ifdef IS_MACOS_X \#ifdef __NO_INLINE__ \#ifdef __OPTIMIZE__ \#ifdef __OPTIMIZE_SIZE__ \#ifdef __PPU__ \#ifdef UNICODE \#ifdef _UNICODE \#ifdef VMS \#ifdef __WCHAR_UNSIGNED__

Helper macros

(having nothing to do with portability)
\#ifdef __ASSEMBLER__ // 1, within assembly blocks \#ifdef __BASE_FILE__ __COUNTER__ // counter starting at 0 __DATE__ // current date string, like "Feb 27 2009" __FILE__ \#ifdef __INCLUDE_LEVEL__ // count of include nests, beginning at 0 __LINE__ \#ifdef __STDC__ // 1, if the compiler conforms to ANSI C 89 \#ifdef __STDC_VERSION__ // 1, for C 90 - "199409L" for C 94 - "199901L" for C 99 \#ifdef __STDC_HOSTED__ // the target platform natively supports all C stdlib facilities __TIME__ // time of pre-compilation, like "21:30:17" __TIMESTAMP__ // date and time of pre-compilation, like "Tue Apr 25 21:30:17 2005" __VA_ARGS__ // lets macros have variable length argument lists \#ifdef VERBOSE // 2 for trace_message
when writing C-language preprocessor macros taking arguments, you can 'glue' them together with the '##'-operator.

Recent Changes (All) | Edit SideBar Page last modified on March 22, 2009, at 01:17 PM Edit Page | Page History
Powered by TechnoloWiki