$Assertions: what changed
Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.
| Old | New | Line | |
|---|---|---|---|
| 1 | - | ||
| 1 | + | Back to [[local compiler directives]]. | |
| 2 | 2 | ||
| 3 | - | ||
| 4 | - | ||
| 3 | + | The local compiler directive **\$C** or **\$ASSERTIONS**: | |
| 5 | 4 | ||
| 6 | - | ||
| 7 | - | ||
| 5 | + | - is used for error detection; | |
| 6 | + | - determines whether an expression is compiled or not. If the directive is active, then the Assert expression is compiled. | |
| 8 | 7 | ||
| 9 | - | ||
| 10 | - | ||
| 8 | + | Examples: | |
| 9 | + | ||
| 10 | + | ``` pascal | |
| 11 | 11 | ... | |
| 12 | - | ||
| 13 | - | ||
| 14 | - | ||
| 15 | - | ||
| 16 | - | ||
| 12 | + | {$ASSERTIONS ON} | |
| 13 | + | ... | |
| 14 | + | Assert(BooleanExpression, AssertMessage); | |
| 15 | + | ... | |
| 17 | 16 | ``` | |
| 17 | + | ||
| 18 | + | ``` pascal | |
| 18 | 19 | ... | |
| 19 | - | ||
| 20 | - | ||
| 21 | - | ||
| 22 | - | ||
| 20 | + | {$C ON} | |
| 21 | + | ... | |
| 22 | + | Assert(BooleanExpression); | |
| 23 | + | ... | |
| 23 | 24 | ``` | |
| 24 | 25 | ||
| 25 | - | ||
| 26 | + | If the *BooleanExpression* is false, an optional error message (AssertMessage) is output with the file name, the line number and the address and the program aborts with Runtime error 227. If *BooleanExpression* is true, program execution continues normally. If assertions are not enabled at compile time, the Assert routine does nothing, and no code is generated for the Assert call. | |
| 26 | 27 | ||
| 27 | 28 | ## see also | |
| 28 | 29 | ||
| 29 | - | ||
| 30 | + | - [`$C` or `$ASSERTIONS`: Assertion support](https://freepascal.org/docs-html/current/prog/progsu5.html) in the Programmer’s Guide | |
| 30 | 31 | ||
| 31 | 32 | --- | |
| 32 | - | ||
| 33 | + | *From the Free Pascal wiki, page "$Assertions", as it stood on 2021-02-11 after a change by Kai Burghardt, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* |
