• C语言条件编译


    使用与平台有关的C语言函数,可能会使得程序不具有可移植性。比如Socket编程、多线程编程等是与平台有关的。

    若想将程序做成平台无关的就需要用到与平台相关的条件编译

    下面转自:http://blog.csdn.net/immcss/article/details/3881827

      • 编译器
        • GCC
          #ifdef __GNUC__
          • #if __GNUC__ >= 3 // GCC3.0以上
        • Visual C++
          #ifdef _MSC_VER(非VC编译器很多地方也有定义)
          • #if _MSC_VER >=1000 // VC++4.0以上
          • #if _MSC_VER >=1100 // VC++5.0以上
          • #if _MSC_VER >=1200 // VC++6.0以上
          • #if _MSC_VER >=1300 // VC2003以上
          • #if _MSC_VER >=1400 // VC2005以上
        • Borland C++
          #ifdef __BORLANDC__
      • UNIX
        • UNIX
          #ifdef __unix
          or
          #ifdef __unix__
        • Linux
          #ifdef __linux
          or
          #ifdef __linux__
        • FreeBSD
          #ifdef __FreeBSD__
        • NetBSD
          #ifdef __NetBSD__
      • Windows
        • 32bit
          #ifdef _WIN32(或者WIN32)
        • 64bit
          #ifdef _WIN64
        • GUI  App
          #ifdef _WINDOWS 
        • CUI  App
          #ifdef _CONSOLE
        • Windows的Ver … WINVER
          ※ PC机Windows(95/98/Me/NT/2000/XP/Vista)和Windows CE都定义了
          • #if (WINVER >= 0x030a) // Windows 3.1以上
          • #if (WINVER >= 0x0400) // Windows 95/NT4.0以上
          • #if (WINVER >= 0x0410) // Windows 98以上
          • #if (WINVER >= 0x0500) // Windows Me/2000以上
          • #if (WINVER >= 0x0501) // Windows XP以上
          • #if (WINVER >= 0x0600) // Windows Vista以上
        • Windows 95/98/Me的Ver … _WIN32_WINDOWS
          • MFC App、PC机上(Windows CE没有定义)
            #ifdef _WIN32_WINDOWS
          • #if (_WIN32_WINDOWS >= 0x0400) // Windows 95以上
          • #if (_WIN32_WINDOWS >= 0x0410) // Windows 98以上
          • #if (_WIN32_WINDOWS >= 0x0500) // Windows Me以上
        • Windows NT的Ver … _WIN32_WINNT
          • #if (_WIN32_WINNT >= 0x0500) // Windows 2000以上
          • #if (_WIN32_WINNT >= 0x0501) // Windows XP以上
          • #if (_WIN32_WINNT >= 0x0600) // Windows Vista以上
        • Windows CE(PocketPC
          #ifdef _WIN32_WCE
        • Windows CE … WINCEOSVER
        • Windows CE
          WCE_IF
        • Internet Explorer的Ver … _WIN32_IE 
      • Cygwin
        • Cygwin
          #ifdef __CYGWIN__
        • 32bit版Cygwin(现在好像还没有64bit版)
          #ifdef __CYGWIN32__
        • MinGW(-mno-cygwin指定)
          #ifdef __MINGW32__

    程序测试:

     1 #include<stdio.h>
     2 int main()
     3 {
     4     printf("The OS :");
     5     #ifdef __linux
     6         printf("Linux
    ");
     7     #endif
     8 
     9     #ifdef _WIN32
    10         printf("win 32
    ");
    11     #endif
    12 
    13     #ifdef _WIN64
    14         printf("win 64
    ");
    15     #endif
    16 
    17     printf("The Compiler : ");
    18     #ifdef __GNUC__
    19         printf("GCC
    ");
    20     #endif
    21     #ifdef _MSC_VER
    22         printf("VC
    ");
    23     #endif
    24     printf("Test Over!!!");
    25     return 0;
    26 }

    执行结果:

    win7_32 CodeBlocks

    Ubuntu_32 gcc

     

  • 相关阅读:
    实例
    LR接口测试---webservices
    LR常用函数整理
    Codeforces Round #639 (Div. 2) A. Puzzle Pieces
    Codeforces Round #640 (Div. 4)全部七题
    POJ3177 Redundant Paths(e-DCC+缩点)
    洛谷P3469 [POI2008]BLO-Blockade(割点)
    洛谷P3275 [SCOI2011]糖果(缩点+拓扑序DP)
    POJ1236 Network of Schools(强连通分量)
    P3387 【模板】缩点(Tarjan求强连通分量)
  • 原文地址:https://www.cnblogs.com/xudong-bupt/p/3521487.html
Copyright © 2020-2023  润新知