Pre-defined C/C++ Compiler Macros
The macros are found here:
General guidelines are found here:
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_VER
is
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: VersionNormalization
Wiki: FeatureMacros
Wiki: Endianness
Wiki: Standards
Wiki: Compilers
Wiki: Libraries
Wiki: OperatingSystems
Wiki: Architectures
相關文章
- Cannot find a C++ compiler that supports both C++11 and the specified C++ flags.C++Compile
- Use any C++ Compiler with Visual StudioC++Compile
- configure: error: C++ compiler cannot create executablesErrorC++Compile
- COMPILER simplified C programminCompile
- linux下安裝安裝pcre-8.32 configure: error: You need a C++ compiler for C++ supportLinuxErrorC++Compile
- 【轉】fatal error C1189: #error : missing -D__STDC_CONSTANT_MACROS / #define __STDC_CONSTANT_MACROSErrorMacROS
- error: #error This file requires compiler and library support for the ISO C++ 2011 standard.ErrorUICompileC++
- 用Scala macros實現DCIMacROS
- C++::My Effective C++C++
- cgo: C compiler "gcc" not found 報錯安裝gccGoCompileGC
- AIX 6.1安裝apache報no acceptable C compiler foundAIApacheCompile
- Snippet CompilerCompile
- 【C/C++】 C++暫存器優化C++優化
- 【C++】C++之Lambda表示式C++
- 【C++】C++基礎知識C++
- C/C++工具C++
- C 與 C++C++
- 字串(C/C++)字串C++
- C/C++ 面試C++面試
- C++C++
- Laravel 通過 Macros 實現列印原生 MySQLLaravelMacROSMySql
- 【C++】 C++知識點總結C++
- [C++之旅] 7 C++類和物件C++物件
- 【C++】C++之型別轉換C++型別
- [C++]C++程式設計例項C++程式設計
- C++ Primer!C++的“倚天劍”C++
- 【C++】C++的位元組對齊C++
- 【C/C++】c++多程式與hiredis的淺使用C++Redis
- C/C++—— 一個特別奇怪的C++程式C++
- Compiler.phpCompilePHP
- 學懂現代C++——《Effective Modern C++》之轉向現代C++C++
- (轉貼) C++,C#,Java功能比較 (.NET) (C#) (C/C++)C++C#Java
- c/c++面試整理C++面試
- 從C到C++C++
- c/c++ 面試題C++面試題
- C/C++自學之路C++
- C/C++複習C++
- C++呼叫C介面C++