#predicate (answer)You must use a properly formed identifier for predicate. The value of answer can be any sequence of words; all characters are significant except for leading and trailing whitespace, and differences in internal whitespace sequences are ignored. Thus, x +y is different from x+y but equivalent to x +y. ) is not allowed in an answer.
What follows is a conditional to test whether the answer answer is asserted for the predicate predicate.
#if #predicate (answer)There may be more than one answer asserted for a given predicate. If you omit the answer, you can test whether any answer is asserted for predicate.
#if #predicateMost of the time, the assertions you test will be predefined assertions. GNU C provides three predefined predicates: system, cpu, and machine.
#system (gnu) #system (mach) #system (mach 3) #system (mach 3. subversion) #system (hurd) #system (hurd version)Perhaps there are others. The alternatives with more or less version information let you ask more or less detailed questions about the type of system software.
On a Unix system, you would find #system (unix) and perhaps one of: #system (aix), #system (bsd), #system (hpux), #system (lynx), #system (mach), #system (posix), #system (svr3), #system (svr4), or #system (xpg4) with possible version numbers following.
Other values for system are #system (mvs) and #system (vms).
Note:
Many Unix C compilers provide
only one answer for the system
assertion: #system
(unix), if they
support assertions at all. This is less than useful.
An assertion with a multi-word answer is completely different from several assertions with individual single-word answers. For example, the presence of system (mach 3.0) does not mean that system (3.0) is true. It also does not directly imply system (mach), but in GNU C, that last will normally be asserted as well. The current list of possible assertion values for cpu is: #cpu (a29k), #cpu (alpha), #cpu (arm), #cpu (clipper), #cpu (convex), #cpu (elxsi), #cpu (tron), #cpu (h8300), #cpu (i370), #cpu (i386), #cpu (i860), #cpu (i960), #cpu (m68k), #cpu (m88k), #cpu (mips), #cpu (ns32k), #cpu (hppa), #cpu (pyr), #cpu (ibm032), #cpu (rs6000), #cpu (sh), #cpu (sparc), #cpu (spur), #cpu (tahoe), #cpu (vax), #cpu (we32000).
You can create assertions within a C program using #assert, with the following input.
#assert predicate (answer)Note:
Each time you do this, you assert a new true answer for predicate. Asserting one answer does not invalidate previously asserted answers; they all remain true. The only way to remove an assertion is with #unassert. #unassert has the same syntax as #assert. You can also remove all assertions about predicate using the following example’s statement.
#unassert predicateYou can also add or cancel assertions using command options when you run gcc or cpp. See Invoking the C preprocessor.