GCC dump preprocessor defines

后端 未结 6 2192
既然无缘
既然无缘 2020-11-22 14:28

Is there a way for gcc/g++ to dump its preprocessor defines from the command line? I mean things like __GNUC__, __STDC__, and so on.

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-22 15:06

    I usually do it this way:

    $ gcc -dM -E - < /dev/null
    

    Note that some preprocessor defines are dependent on command line options - you can test these by adding the relevant options to the above command line. For example, to see which SSE3/SSE4 options are enabled by default:

    $ gcc -dM -E - < /dev/null | grep SSE[34]
    #define __SSE3__ 1
    #define __SSSE3__ 1
    

    and then compare this when -msse4 is specified:

    $ gcc -dM -E -msse4 - < /dev/null | grep SSE[34]
    #define __SSE3__ 1
    #define __SSE4_1__ 1
    #define __SSE4_2__ 1
    #define __SSSE3__ 1
    

    Similarly you can see which options differ between two different sets of command line options, e.g. compare preprocessor defines for optimisation levels -O0 (none) and -O3 (full):

    $ gcc -dM -E -O0 - < /dev/null > /tmp/O0.txt
    $ gcc -dM -E -O3 - < /dev/null > /tmp/O3.txt
    $ sdiff -s /tmp/O0.txt /tmp/O3.txt 
    #define __NO_INLINE__ 1        <
                                   > #define __OPTIMIZE__ 1
    

提交回复
热议问题