8.2 #assert

The #assert preprocessing extensions of System V release 4 are permitted. These enable definition and testing of predicate names.

Such names are in a namespace distinct from all other names, including macro names.

Syntax

#assert name
#assert name[(token-sequence)]
Where:
name
is a predicate name
token-sequence
is an optional sequence of tokens.
If the token sequence is omitted, name is not given a value.
If the token sequence is included, name is given the value token-sequence.

Usage

You can test a predicate name defined using #assert in a #if expression, for example:
#if #name(token-sequence)
This has the value 1 if a #assert of the name name with the token-sequence token-sequence has appeared, and 0 otherwise.
A predicate can have multiple values. That is, subsequent assertions do not override preceding assertions.

Example

The following example assigns multiple values and shows the results #if expressions:
#assert foo(one)      // Assigns the value "one"
#assert foo(two)      // Assigns the value "two"
#assert foo(three)    // Assigns the value "three"
#unassert foo(two)    // Unassigns the value "two"
        
#if #foo(one)...      // 1
#if #foo(two)...      // 0, because of #unassert
#if #foo(three)...    // 1
#if #foo(four)...     // 0, because this value was never asserted
Related reference
8.4 #unassert
Non-ConfidentialPDF file icon PDF versionARM DUI0375F
Copyright © 2007, 2008, 2011, 2012, 2014 ARM. All rights reserved.