diff options
| author | Tyge Løvset <[email protected]> | 2021-10-04 19:28:17 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2021-10-04 19:28:17 +0200 |
| commit | 20645dbb5ca19015d100f33277c7fcf60bd4bf93 (patch) | |
| tree | 1e54746437047c9c19cf4f2115070f29728ec189 /docs | |
| parent | 35997591de5a448752734c822b0f1003e08853a5 (diff) | |
| download | STC-modified-20645dbb5ca19015d100f33277c7fcf60bd4bf93.tar.gz STC-modified-20645dbb5ca19015d100f33277c7fcf60bd4bf93.zip | |
Added c_autodefer() macro (again). Depressed warning with c_no_compare().
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/ccommon_api.md | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/docs/ccommon_api.md b/docs/ccommon_api.md index 902b33f5..83f5dc6f 100644 --- a/docs/ccommon_api.md +++ b/docs/ccommon_api.md @@ -2,7 +2,7 @@ The following handy macros are safe to use, i.e. have no side-effects. -### c_autoscope, c_autovar, c_auto, c_exitauto +### c_auto, c_autovar, c_autoscope, c_autodefer General ***defer*** mechanics for resource acquisition. These macros allows to specify the release of the resource where the resource acquisition takes place. Makes it easier to verify that resources are released. @@ -13,10 +13,11 @@ macros, as one must always make sure to unwind temporary allocated resources bef | Usage | Description | |:---------------------------------------|:---------------------------------------------------| -| `c_autoscope (init, end...)` | Execute `init`. Defer `end...` to end of block | -| `c_autovar (Type var=init, end...)` | Declare `var`. Defer `end...` to end of block | | `c_auto (Type, var...)` | `c_autovar (Type var=Type_init(), Type_del(&var))` | -| `c_exitauto;` | Break out of a `c_auto*`-block/scope | +| `c_autovar (Type var=init, end...)` | Declare `var`. Defer `end...` to end of block | +| `c_autoscope (init, end...)` | Execute `init`. Defer `end...` to end of block | +| `c_autodefer (end...)` | Defer `end...` to end of block | +| `c_exitauto;` | Break safely out of a `c_auto*`-block/scope | For multiple variables, use either multiple **c_autovar** in sequence, or declare variable outside scope and use **c_autoscope**. Also, **c_auto** support up to 3 variables. @@ -45,7 +46,7 @@ c_autoscope (mydata_init(&data), mydata_destroy(&data)) } cstr s1 = cstr_lit("Hello"), s2 = cstr_lit("world"); -c_autoscope (0, cstr_del(&s1), cstr_del(&s2)) +c_autodefer (cstr_del(&s1), cstr_del(&s2)) { printf("%s %s\n", s1.str, s2.str); } |
