{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

We discourage their use in new code in some cases we

Info iconThis preview shows pages 58–60. Sign up to view the full content.

View Full Document Right Arrow Icon
We discourage their use in new code. In some cases, we plan to remove the feature in a future version of GCC. 11.3.1 Assertions Assertions 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. Assertions were intended to provide a more systematic way to describe the compiler’s target system and we added them for compatibility with existing compilers. 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 less portable than the use of system-specific predefined macros. We recommend you do not use them at all. An assertion looks like this: # predicate ( answer ) predicate must be a single identifier. answer 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, (x + y) is different from (x+y) but equivalent to ( x + y ) . Parentheses do not nest inside an answer. To test an assertion, you write it in an ‘ #if ’. For example, this conditional succeeds if either vax or ns16000 has been asserted as an answer for machine . #if #machine (vax) || #machine (ns16000) You can test whether any answer is asserted for a predicate by omitting the answer in the conditional: #if #machine Assertions are made with the ‘ #assert ’ directive. Its sole argument is the assertion to make, without the leading ‘ # ’ that identifies assertions in conditionals. #assert predicate ( answer ) 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. Assertions can be canceled with the ‘ #unassert ’ directive. It has the same syntax as #assert ’. In that form it cancels only the answer which was specified on the ‘ #unassert line; other answers for that predicate remain true. You can cancel an entire predicate by leaving out the answer: #unassert predicate In either form, if no such assertion has been made, ‘ #unassert ’ has no effect. You can also make or cancel assertions using command line options. See Chapter 12 [Invocation], page 56 .
Background image of page 58

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Chapter 11: Implementation Details 55 11.4 Differences from previous versions This section details behavior which has changed from previous versions of CPP. We do not plan to change it again in the near future, but we do not promise not to, either. The “previous versions” discussed here are 2.95 and before. The behavior of GCC 3.0 is mostly the same as the behavior of the widely used 2.96 and 2.97 development snapshots.
Background image of page 59
Image of page 60
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}