summaryrefslogtreecommitdiffhomepage
path: root/docs/ccommon_api.md
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2021-11-21 23:17:24 +0100
committerTyge Løvset <[email protected]>2021-11-21 23:17:24 +0100
commitee09c3627dee4eb2ec87fda9783be1bb15e132d9 (patch)
treeecc646a430e75f618e00c2a95ce2372e1021ba5d /docs/ccommon_api.md
parent879f7a1c5637a5f67d430d3583fc7ba34b687234 (diff)
downloadSTC-modified-ee09c3627dee4eb2ec87fda9783be1bb15e132d9.tar.gz
STC-modified-ee09c3627dee4eb2ec87fda9783be1bb15e132d9.zip
BREAKING CHANGE: Replaced c_new(T) with c_new(T, ...). This now is similar to the c++ new operator. The previous c_new(T) is renamed to c_alloc(T), and c_new_n(T,n) => c_alloc_n(T,n). Old usage of c_new() will fail as it requires additional argument. Sorry for the inconvenience.
Diffstat (limited to 'docs/ccommon_api.md')
-rw-r--r--docs/ccommon_api.md13
1 files changed, 9 insertions, 4 deletions
diff --git a/docs/ccommon_api.md b/docs/ccommon_api.md
index 9a309835..db89120e 100644
--- a/docs/ccommon_api.md
+++ b/docs/ccommon_api.md
@@ -133,17 +133,22 @@ int arr[] = {1, 2, 3};
c_apply_n(cvec_i, push_back, &vec, arr, c_arraylen(arr));
```
-### c_new, c_new_n, c_del, c_make
+### c_new, c_alloc, c_alloc_n, c_del, c_make
| Usage | Meaning |
|:-------------------------------|:----------------------------------------|
-| `c_new (type)` | `(type *) c_malloc(sizeof(type))` |
-| `c_new_n (type, N)` | `(type *) c_malloc((N)*sizeof(type))` |
+| `c_new (type, value)` | Move value to a new object on the heap |
+| `c_alloc (type)` | `(type *) c_malloc(sizeof(type))` |
+| `c_alloc_n (type, N)` | `(type *) c_malloc((N)*sizeof(type))` |
| `c_del (ctype, &c1, ..., &cN)` | `ctype_del(&c1); ... ctype_del(&cN)` |
| `c_make(type){value...}` | `(type){value...}` // c++ compatability |
```c
-int* array = c_new_n (int, 100);
+struct Pnt { double x, y, z; };
+struct Pnt *pnt = c_new (struct Pnt, {1.2, 3.4, 5.6});
+c_free(pnt);
+
+int* array = c_alloc_n (int, 100);
c_free(array);
cstr a = cstr_from("Hello"), b = cstr_from("World");