zoukankan      html  css  js  c++  java
  • 预定义宏__GNUC__和_MSC_VER

     http://www.cnblogs.com/whiteyun/archive/2010/09/05/1818491.html

    一、预定义__GNUC__宏

        1 __GNUC__ 是gcc编译器编译代码时预定义的一个宏。需要针对gcc编写代码时, 可以使用该宏进行条件编译。

        2 __GNUC__ 的值表示gcc的版本。需要针对gcc特定版本编写代码时,也可以使用该宏进行条件编译。

        3 __GNUC__ 的类型是“int”,该宏被扩展后, 得到的是整数字面值。可以通过仅预处理,查看宏扩展后的文本。

    示例:

      #include <assert.h>

      #include <stdio.h>

      #include <typeinfo>
      #ifndef __GNUC__

        #error sample for gcc compiler

      #else

        /* use gcc special extension: #warning , __attribute__, etc.  */

      #endif

      int main() 

      {    

        printf("hello gcc %d ",__GNUC__);    

        assert( typeid(__GNUC__)==typeid(int) );    

        printf("press Enter to exit ");    

        (void)getchar();

      }


    二、预定义_MSC_VER宏

        1 _MSC_VER是微软C/C++编译器——cl.exe编译代码时预定义的一个宏。需要针对cl编写代码时, 可以使用该宏进行条件编译。

        2 _MSC_VER的值表示cl的版本。需要针对cl特定版本编写代码时, 也可以使用该宏进行条件编译。

        3 _MSC_VER的类型是"int"。该宏被扩展后,得到的是整数字面值。可以通过仅预处理, 查看宏扩展后的文本。

    示例:

      /* _MSC_VER\_MSC_VER.cpp */

      #include <stdio.h>

       #include <stdlib.h>

       #include <typeinfo>

       #define TO_LITERAL(text) TO_LITERAL_(text)

       #define TO_LITERAL_(text) #text

       #ifndef _MSC_VER

         #error sample for msvc compiler

      #else

        /* use msvc special extension: #pragma message,__declspec,__stdcall,etc. */

        #pragma message("---------------------------------------- ")

        #pragma message("---------------------------------------- ")

        #pragma message("---------- hello msvc " TO_LITERAL(_MSC_VER) " -------------")

        #pragma message(" ---------------------------------------- ")

        #pragma message("---------------------------------------- ")

        extern __declspec(dllimport) void __stdcall declare_but_dont_reference(void);

       #endif
        

      int main()

      {    

        printf("hello msvc, version=%d ",_MSC_VER);    

        printf("typeof _MSC_VER="%s" ",typeid(_MSC_VER).name());    

        system("pause"); /* msvc only on windows? */    

        return 0;

      }

  • 相关阅读:
    15、TSA数据上传(https://www.ncbi.nlm.nih.gov/genbank/tsaguide/#SP)
    14、SRA数据上传
    14、批量处理文件
    .net mvc 利用分部视图局部刷新.
    观察者模式(Observer)
    内存和性能
    DOM中的事件对象(event)
    HTML事件处理程序
    惰性载入函数
    Comet之SSE(Server
  • 原文地址:https://www.cnblogs.com/davytitan/p/4459177.html
Copyright © 2011-2022 走看看