Pre-defined C/C++ Compiler Macros
2013-12-05 10:45
253 查看
Standards
Compilers
Libraries
Operating systems
Architectures
General guidelines are found here:
Version normalization
Feature macros
Endianness
Please send updates/corrections to predef-contribute.
Introduction
C and C++ compilers automatically define certain macros that can be used to check for compiler or operating system features. This is useful when writing portable software.These pages lists various pre-defined compiler macros that can be used to identify standards, compilers, operating systems, hardware architectures, and even basic run-time libraries at compile-time.
For example, if we want to use a generic or opaque pointer type, we use void pointers. However, ancient K&R compilers (from the time before the first ANSI C standard) do not support void pointers. Instead we can define our own type:
#if defined(__STDC__) || defined(__cplusplus) || defined(_MSC_EXTENSIONS) typedef void * t_pointer; #else typedef char * t_pointer; #endif
Another example, Microsoft Visual C++ version 4.2 added a pragma to reduce compilation times by only including a file once (if
_MSC_VERis
not defined then it will evaluate to 0 (zero) — however, some compilers may complain about an undefined macro)
#if defined(_MSC_VER) && (_MSC_VER >= 1020) #pragma once #endif
The macros contained in these pages have been obtained through vendor documentation, the defines script, contributors, and third-party source code. No guarantee about the correctness
of the macros is given.
An often-used alternative is Autoconf, which is a more powerful tool to examine various types of features, including compilation options. However, Autoconf is fairly
Unix-centric, and requires a Unix layer on other platforms (e.g. Cygwin on Windows). Other alternatives are Buildtool, CMake, SCons, PMK, Jam, Ant,
andBakefile.
Contributors
Bjorn Reese, Daniel Stenberg, Greg Roelofs, Steven G. Johnson, Wlodzimierz ABX Skiba, Marc Finet, Philip Newton, Mitchell Charity, Christian Klutz, Seo Sanghyeon, Chris Adami, Geoff Clare, Dan Fandrich, Mike Gorchak, Yuri D'Elia, Gynvael Coldwind, Alain Tauch,Vadim Zeitlin, Steve White, Thomas David Rivers, Tom Honermann, Martin Mitas, Dinesh Chhadwa, Erik Faye-Lund, Leo Davis, Paul Hsieh, Roland Schwarz, Darko Kolakovic, Andy Buonviri, Ming Kin Lai, Kent Johnson, Helmut Bauer, Oliver Schneider, Ron Pimblett, Jose
Luis Rodriguez Garcia, Jeroen Ruigrok van der Werven, Uffe Jakobsen, Bryan Ashby, Bruno Haible, Artur Bac, Terry Schwarz, Leo Davis, Markus Duft, William Dang, Paul Green, Ruben Van Boxem, Pau Garcia i Quiles, Mikulas Patocka, Leo Davis, Mark Ferry, Holger
Machens, Simon Watts, Paul Hargrove, Hans-Christoph Steiner, Gerald Combs, Denys Bulant, Massimo Morara, Jeremy Bennett, Guillem Jover, Riku Voipio, Jacques Pelletier, Mark Jarvin, Georg Sauthoff, Scot Jenkins, Grzegorz Brzęczyszczykiewicz, John Dallman, Gianmichele
Toglia.
Related
Wiki: VersionNormalizationWiki: FeatureMacros
Wiki: Endianness
Wiki: Standards
Wiki: Compilers
Wiki: Libraries
Wiki: OperatingSystems
Wiki: Architectures
相关文章推荐
- 编译器预定义宏(Pre-defined C/C++ Compiler Macros)
- Pre-defined Compiler Macros
- C/C++ tip: How to detect the operating system type using compiler predefined macros
- recompiled header file is from a previous version of the compiler, or the precompiled header is C++
- 在WinDOWS X64下 Cuda NVCC 与 Intel C/C++ compiler联合使用的问题
- Leetcode_c++:Construct Binary Tree from Preorder and Inorder Traversal(105)
- 卸载Intel C++ Compiler后Visual C++ 6.0不能工作了
- 关于C++中报Error:new types may not be defined in a return type问题
- Question 29: The C++ code below generates a compiler error. Which of the following solutions can be used to correctly access the
- 【android开发】errors running builder 'Android Pre Compiler' 解决方法
- Using Intel® C++ Compiler with the Eclipse* IDE on Linux*
- windows平台使用Microsoft Visual C++ Compiler for Python 2.7编译python扩展
- [error]configure: error: You need a C++ compiler for C++ support.
- some collected macros for C++
- #error This file requires compiler and library support for the ISO C++ 2011错误解决办法
- Using GCC’s C++ Compiler
- configure: error: C++ compiler cannot create executables
- Do-While and if-else statements in C/C++ macros
- Microsoft Visual C++ Compiler for Python 2.7
- How a C++ compiler implements exception handling