summaryrefslogtreecommitdiffhomepage
path: root/docs
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2021-06-01 20:46:09 +0200
committerTyge Løvset <[email protected]>2021-06-01 20:46:09 +0200
commit18de7e809d470c84fec9c420133e3a5a036a4239 (patch)
tree88abab137f32a98a388e89e3734fb4dba38d8c06 /docs
parent032b6d654a1125fe172ef225fdacb87ac3e1fdc5 (diff)
downloadSTC-modified-18de7e809d470c84fec9c420133e3a5a036a4239.tar.gz
STC-modified-18de7e809d470c84fec9c420133e3a5a036a4239.zip
1. Added c_forscope() macro. Similar to c_forvar() and c_fordefer().
2. Added *experimental* forward declare for cvec: No API changes: typedef struct person Person; // forward declare cvec_prs forward_cvec(prs, Person); ... // complete definition: specify c_false as very last parameter. using_cvec(prs, Person, c_no_compare, person_del, person_clone, c_default_toraw, Person, c_false);
Diffstat (limited to 'docs')
-rw-r--r--docs/ccommon_api.md17
1 files changed, 9 insertions, 8 deletions
diff --git a/docs/ccommon_api.md b/docs/ccommon_api.md
index b4b548a8..2d671cd8 100644
--- a/docs/ccommon_api.md
+++ b/docs/ccommon_api.md
@@ -8,19 +8,20 @@ resource near the resource acquisition, and makes it easier to verify that resou
**Note**: These macros are one-time executed **for**-loops. ***Only*** use `continue` in order to break out
of a `c_forvar` / `c_fordefer`-block. ***Do not*** use `return`, `goto` or `break`, as it will prevent the
-`release`-statement to be executed at the end. The same applies for `c_forbuffer`. This is not particular to
+`end`-statement to be executed at the end. The same applies for `c_forbuffer`. This is not particular to
the `c_for*()` macros, as one must always make sure to unwind temporary allocated resources before `return` in C.
The **c_forbuffer** uses stack memory if buffer is <= to 256 bytes, othewise it uses the slower heap memory.
-| Usage | Description |
-|:---------------------------------|:--------------------------------------------------|
-| `c_forvar (acquire, release...)` | Do `acquire`. Defer `release` to end of block |
-| `c_fordefer (release...)` | Defer execution of `release` to end of block |
-| `c_forbuffer (buf, type, n)` | Declare, allocate and free memory buffer |
+| Usage | Description |
+|:---------------------------------------|:--------------------------------------------------|
+| `c_forvar (Type var=init, end...)` | Declare `var`. Defer `end` to end of block |
+| `c_forscope (start, end)` | Execute `start`. Defer `end` to end of block |
+| `c_fordefer (end...)` | Defer execution of `end` to end of block |
+| `c_forbuffer (buf, type, n)` | Declare, allocate and free memory buffer |
-The `acquire`argument must be of the form: `type var = GetResource`. For multiple variables, use multiple
-**c_forvar** in sequence, or if variables are of same type, the **c_arg** macro can be used:
+For multiple variables, use either multiple **c_forvar** in sequence, or if variables are of same type,
+the **c_arg** macro can be used:
```c
c_forvar (c_arg(cstr s1 = cstr_lit("Hello"), s2 = cstr_lit("world")), cstr_del(&s1), cstr_del(&s2))
{