Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| intro_example:assertions [2025/05/17 12:03] – rajit | intro_example:assertions [2025/05/17 12:07] (current) – rajit | ||
|---|---|---|---|
| Line 23: | Line 23: | ||
| < | < | ||
| --[ERROR]-> | --[ERROR]-> | ||
| + | In expanding buffer< | ||
| In expanding ::< | In expanding ::< | ||
| - | Error on or near line number XXXX | + | Error on or near line number XXXX. |
| id: b[0].L | id: b[0].L | ||
| FATAL: Identifer conditionally created, but used when it does not exist | FATAL: Identifer conditionally created, but used when it does not exist | ||
| </ | </ | ||
| + | The definition, as written, does not support zero-length buffers. Rather than getting a message at expansion time that may not be as understandable to a user (especially of a pre-defined library), we can add an assertion to provide a more meaningful error message to a user of the templated buffer. | ||
| + | |||
| + | <code act> | ||
| + | template< | ||
| + | defproc buffer(chan? | ||
| + | { | ||
| + | { N > 0 : " | ||
| + | onebuf b[N]; // create one-place buffer elements | ||
| + | (i:N-1: b[i+1].L = b[i].R; | ||
| + | b[0].L = L; // connect external input | ||
| + | b[N-1].R = R; // connect external output | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | With this change, the error now looks like the following: | ||
| + | < | ||
| + | --[ERROR]-> | ||
| + | In expanding buffer< | ||
| + | In expanding ::< | ||
| + | Error on or near line number XXXX. | ||
| + | *** Assertion failed *** | ||
| + | | ||
| + | | ||
| + | </ | ||
| + | |||
| + | |||