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

📄 assertions.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="Assertions">Assertions</a>,

Next:<a rel="next" accesskey="n" href="Obsolete-once-only-headers.html#Obsolete%20once-only%20headers">Obsolete once-only headers</a>,

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

<hr><br>

</div>



<h4 class="subsection">Assertions</h4>



   <p><dfn>Assertions</dfn> are a deprecated alternative to macros in writing

conditionals to test what sort of computer or system the compiled

program will run on.  Assertions are usually predefined, but you can

define them with preprocessing directives or command-line options.



   <p>Assertions were intended to provide a more systematic way to describe

the compiler's target system.  However, in practice they are just as

unpredictable as the system-specific predefined macros.  In addition, they

are not part of any standard, and only a few compilers support them. 

Therefore, the use of assertions is <strong>less</strong> portable than the use

of system-specific predefined macros.  We recommend you do not use them at

all.



   <p>An assertion looks like this:



<pre class="example">     #<var>predicate</var> (<var>answer</var>)

     </pre>



<p><var>predicate</var> must be a single identifier.  <var>answer</var> can be any

sequence of tokens; all characters are significant except for leading

and trailing whitespace, and differences in internal whitespace

sequences are ignored.  (This is similar to the rules governing macro

redefinition.)  Thus, <code>(x + y)</code> is different from <code>(x+y)</code> but

equivalent to <code>(&nbsp;x&nbsp;+&nbsp;y&nbsp;)</code>.  Parentheses do not nest inside an

answer.



   <p>To test an assertion, you write it in an <code>#if</code>.  For example, this

conditional succeeds if either <code>vax</code> or <code>ns16000</code> has been

asserted as an answer for <code>machine</code>.



<pre class="example">     #if #machine (vax) || #machine (ns16000)

     </pre>



<p>You can test whether <em>any</em> answer is asserted for a predicate by

omitting the answer in the conditional:



<pre class="example">     #if #machine

     </pre>



   <p>Assertions are made with the <code>#assert</code> directive.  Its sole

argument is the assertion to make, without the leading <code>#</code> that

identifies assertions in conditionals.



<pre class="example">     #assert <var>predicate</var> (<var>answer</var>)

     </pre>



<p>You may make several assertions with the same predicate and different

answers.  Subsequent assertions do not override previous ones for the

same predicate.  All the answers for any given predicate are

simultaneously true.



   <p>Assertions can be canceled with the <code>#unassert</code> directive.  It

has the same syntax as <code>#assert</code>.  In that form it cancels only the

answer which was specified on the <code>#unassert</code> line; other answers

for that predicate remain true.  You can cancel an entire predicate by

leaving out the answer:



<pre class="example">     #unassert <var>predicate</var>

     </pre>



<p>In either form, if no such assertion has been made, <code>#unassert</code> has

no effect.



   <p>You can also make or cancel assertions using command line options. 

See <a href="Invocation.html#Invocation">Invocation</a>.



   </body></html>



⌨️ 快捷键说明

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