본문 바로가기
Programming

Pre-defined C / C++ Compiler Macros

by leanu 2009. 9. 30.

멀티 플랫폼개발이나 , 컴파일러, 중요 라이브러리들을 점검하고자 할때
위와 같은 미리 정의된 매크로들을 사용한다.

아래의 링크에 잘 정리되어 있다. 

아래는 GNU C / C++ 의 버전을 체크하는 부분.

GNU C/C++

TypeMacroDescription
Identification __GNUC__ .
Version __GNUC__ Version
Version __GNUC_MINOR__ Revision
Version __GNUC_PATCHLEVEL__ Patch (introduced in version 3.0)

Please note that the meaning of the __GNUC__ macro has changed subtly over the years, from identifying the GNU C/C++ compiler to identifying any compiler that implements the GNU compiler extensions (see the Feature request - a macro defined for GCC discussion for further information). For example, the Intel C++ on Linux also defines these macros from version 8.1 (see the Intel C++ Compiler 8.1 for Linux Release Notes and Intel Compilers for Linux: Compatibility with GNU Compilers.)

Example

GNU C/C++__GNUC____GNUC_MINOR____GNUC_PATCHLEVEL__
2.7.x 2 7 .
3.0.2 3 0 2

Alternative Version

If you prefer a single version macro, you can define the following yourself.

#if defined(__GNUC__)
# if defined(__GNUC_PATCHLEVEL__)
#  define __GNUC_VERSION__ (__GNUC__ * 10000 \
                            + __GNUC_MINOR__ * 100 \
                            + __GNUC_PATCHLEVEL__)
# else
#  define __GNUC_VERSION__ (__GNUC__ * 10000 \
                            + __GNUC_MINOR__ * 100)
# endif
#endif

The format of this new macro is:

TypeMacroFormatDescription
Version __GNUC_VERSION__ VVRRPP VV = Version
RR = Revision
PP = Patch

Example of Alternative Version

GNU C/C++__GNUC_VERSION__
2.7.x 20700
3.0.2 30002



Visual C++ Version ( _MSC_VER )

 Visual C++ Version _MSC_VER value 
 9.0 1500 
 8.0 1400 
 7.1 1310 
 7.0 1300 
 6.0 1200 
 5.0 1100 


댓글