⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 common-predefined-macros.html

📁 gcc手册
💻 HTML
字号:
<html lang="en">

<head>

<title>The C Preprocessor</title>

<meta http-equiv="Content-Type" content="text/html">

<meta name="description" content="The C Preprocessor">

<meta name="generator" content="makeinfo 4.3">

<link href="http://www.gnu.org/software/texinfo/" rel="generator-home">

<!--

Copyright &copy; 1987, 1989, 1991, 1992, 1993, 1994, 1995, 1996,

1997, 1998, 1999, 2000, 2001, 2002, 2003

Free Software Foundation, Inc.



   <p>Permission is granted to copy, distribute and/or modify this document

under the terms of the GNU Free Documentation License, Version 1.1 or

any later version published by the Free Software Foundation.  A copy of

the license is included in the

section entitled "GNU Free Documentation License".



   <p>This manual contains no Invariant Sections.  The Front-Cover Texts are

(a) (see below), and the Back-Cover Texts are (b) (see below).



   <p>(a) The FSF's Front-Cover Text is:



   <p>A GNU Manual



   <p>(b) The FSF's Back-Cover Text is:



   <p>You have freedom to copy and modify this GNU Manual, like GNU

     software.  Copies published by the Free Software Foundation raise

     funds for GNU development. 

-->

</head>

<body>

<div class="node">

<p>

Node:<a name="Common%20Predefined%20Macros">Common Predefined Macros</a>,

Next:<a rel="next" accesskey="n" href="System-specific-Predefined-Macros.html#System-specific%20Predefined%20Macros">System-specific Predefined Macros</a>,

Previous:<a rel="previous" accesskey="p" href="Standard-Predefined-Macros.html#Standard%20Predefined%20Macros">Standard Predefined Macros</a>,

Up:<a rel="up" accesskey="u" href="Predefined-Macros.html#Predefined%20Macros">Predefined Macros</a>

<hr><br>

</div>



<h4 class="subsection">Common Predefined Macros</h4>



   <p>The common predefined macros are GNU C extensions.  They are available

with the same meanings regardless of the machine or operating system on

which you are using GNU C.  Their names all start with double

underscores.



     <dl>



     <br><dt><code>__GNUC__</code>

     <dd><dt><code>__GNUC_MINOR__</code>

     <dd><dt><code>__GNUC_PATCHLEVEL__</code>

     <dd>These macros are defined by all GNU compilers that use the C

preprocessor: C, C++, and Objective-C.  Their values are the major

version, minor version, and patch level of the compiler, as integer

constants.  For example, GCC 3.2.1 will define <code>__GNUC__</code> to 3,

<code>__GNUC_MINOR__</code> to 2, and <code>__GNUC_PATCHLEVEL__</code> to 1.  They

are defined only when the entire compiler is in use; if you invoke the

preprocessor directly, they are not defined.



     <p><code>__GNUC_PATCHLEVEL__</code> is new to GCC 3.0; it is also present in the

widely-used development snapshots leading up to 3.0 (which identify

themselves as GCC 2.96 or 2.97, depending on which snapshot you have).



     <p>If all you need to know is whether or not your program is being compiled

by GCC, you can simply test <code>__GNUC__</code>.  If you need to write code

which depends on a specific version, you must be more careful.  Each

time the minor version is increased, the patch level is reset to zero;

each time the major version is increased (which happens rarely), the

minor version and patch level are reset.  If you wish to use the

predefined macros directly in the conditional, you will need to write it

like this:



     <pre class="example">          /* Test for GCC &gt; 3.2.0 */

          #if __GNUC__ &gt; 3 || \

              (__GNUC__ == 3 &amp;&amp; (__GNUC_MINOR__ &gt; 2 || \

                                 (__GNUC_MINOR__ == 2 &amp;&amp; \

                                  __GNUC_PATCHLEVEL__ &gt; 0))

          </pre>



     <p>Another approach is to use the predefined macros to

calculate a single number, then compare that against a threshold:



     <pre class="example">          #define GCC_VERSION (__GNUC__ * 10000 \

                               + __GNUC_MINOR__ * 100 \

                               + __GNUC_PATCHLEVEL__)

          ...

          /* Test for GCC &gt; 3.2.0 */

          #if GCC_VERSION &gt; 30200

          </pre>



     <p>Many people find this form easier to understand.



     <br><dt><code>__OBJC__</code>

     <dd>This macro is defined, with value 1, when the Objective-C compiler is in

use.  You can use <code>__OBJC__</code> to test whether a header is compiled

by a C compiler or a Objective-C compiler.



     <br><dt><code>__GNUG__</code>

     <dd>The GNU C++ compiler defines this.  Testing it is equivalent to

testing <code>(__GNUC__&nbsp;&amp;&amp;&nbsp;__cplusplus)</code>.



     <br><dt><code>__STRICT_ANSI__</code>

     <dd>GCC defines this macro if and only if the <code>-ansi</code> switch, or a

<code>-std</code> switch specifying strict conformance to some version of ISO C,

was specified when GCC was invoked.  It is defined to <code>1</code>. 

This macro exists primarily to direct GNU libc's header files to

restrict their definitions to the minimal set found in the 1989 C

standard.



     <br><dt><code>__BASE_FILE__</code>

     <dd>This macro expands to the name of the main input file, in the form

of a C string constant.  This is the source file that was specified

on the command line of the preprocessor or C compiler.



     <br><dt><code>__INCLUDE_LEVEL__</code>

     <dd>This macro expands to a decimal integer constant that represents the

depth of nesting in include files.  The value of this macro is

incremented on every <code>#include</code> directive and decremented at the

end of every included file.  It starts out at 0, it's value within the

base file specified on the command line.



     <br><dt><code>__VERSION__</code>

     <dd>This macro expands to a string constant which describes the version of

the compiler in use.  You should not rely on its contents having any

particular form, but it can be counted on to contain at least the

release number.



     <br><dt><code>__OPTIMIZE__</code>

     <dd><dt><code>__OPTIMIZE_SIZE__</code>

     <dd><dt><code>__NO_INLINE__</code>

     <dd>These macros describe the compilation mode.  <code>__OPTIMIZE__</code> is

defined in all optimizing compilations.  <code>__OPTIMIZE_SIZE__</code> is

defined if the compiler is optimizing for size, not speed. 

<code>__NO_INLINE__</code> is defined if no functions will be inlined into

their callers (when not optimizing, or when inlining has been

specifically disabled by <code>-fno-inline</code>).



     <p>These macros cause certain GNU header files to provide optimized

definitions, using macros or inline functions, of system library

functions.  You should not use these macros in any way unless you make

sure that programs will execute with the same effect whether or not they

are defined.  If they are defined, their value is 1.



     <br><dt><code>__CHAR_UNSIGNED__</code>

     <dd>GCC defines this macro if and only if the data type <code>char</code> is

unsigned on the target machine.  It exists to cause the standard header

file <code>limits.h</code> to work correctly.  You should not use this macro

yourself; instead, refer to the standard macros defined in <code>limits.h</code>.



     <br><dt><code>__WCHAR_UNSIGNED__</code>

     <dd>Like <code>__CHAR_UNSIGNED__</code>, this macro is defined if and only if the

data type <code>wchar_t</code> is unsigned and the front-end is in C++ mode.



     <br><dt><code>__REGISTER_PREFIX__</code>

     <dd>This macro expands to a single token (not a string constant) which is

the prefix applied to CPU register names in assembly language for this

target.  You can use it to write assembly that is usable in multiple

environments.  For example, in the <code>m68k-aout</code> environment it

expands to nothing, but in the <code>m68k-coff</code> environment it expands

to a single <code>%</code>.



     <br><dt><code>__USER_LABEL_PREFIX__</code>

     <dd>This macro expands to a single token which is the prefix applied to

user labels (symbols visible to C code) in assembly.  For example, in

the <code>m68k-aout</code> environment it expands to an <code>_</code>, but in the

<code>m68k-coff</code> environment it expands to nothing.



     <p>This macro will have the correct definition even if

<code>-f(no-)underscores</code> is in use, but it will not be correct if

target-specific options that adjust this prefix are used (e.g. the

OSF/rose <code>-mno-underscores</code> option).



     <br><dt><code>__SIZE_TYPE__</code>

     <dd><dt><code>__PTRDIFF_TYPE__</code>

     <dd><dt><code>__WCHAR_TYPE__</code>

     <dd><dt><code>__WINT_TYPE__</code>

     <dd>These macros are defined to the correct underlying types for the

<code>size_t</code>, <code>ptrdiff_t</code>, <code>wchar_t</code>, and <code>wint_t</code>

typedefs, respectively.  They exist to make the standard header files

<code>stddef.h</code> and <code>wchar.h</code> work correctly.  You should not use

these macros directly; instead, include the appropriate headers and use

the typedefs.



     <br><dt><code>__CHAR_BIT__</code>

     <dd>Defined to the number of bits used in the representation of the

<code>char</code> data type.  It exists to make the standard header given

numerical limits work correctly.  You should not use

this macro directly; instead, include the appropriate headers.



     <br><dt><code>__SCHAR_MAX__</code>

     <dd><dt><code>__WCHAR_MAX__</code>

     <dd><dt><code>__SHRT_MAX__</code>

     <dd><dt><code>__INT_MAX__</code>

     <dd><dt><code>__LONG_MAX__</code>

     <dd><dt><code>__LONG_LONG_MAX__</code>

     <dd>Defined to the maximum value of the <code>signed char</code>, <code>wchar_t</code>,

<code>signed short</code>,

<code>signed int</code>, <code>signed long</code>, and <code>signed long long</code> types

respectively.  They exist to make the standard header given numerical limits

work correctly.  You should not use these macros directly; instead, include

the appropriate headers.



     <br><dt><code>__USING_SJLJ_EXCEPTIONS__</code>

     <dd>This macro is defined, with value 1, if the compiler uses the old

mechanism based on <code>setjmp</code> and <code>longjmp</code> for exception

handling.



     <br><dt><code>__NEXT_RUNTIME__</code>

     <dd>This macro is defined, with value 1, if (and only if) the NeXT runtime

(as in <code>-fnext-runtime</code>) is in use for Objective-C.  If the GNU

runtime is used, this macro is not defined, so that you can use this

macro to determine which runtime (NeXT or GNU) is being used. 

</dl>



   </body></html>



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -