Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
tadd committed Oct 28, 2024
1 parent e768734 commit 2cb603a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,23 @@ printf("new length: %zu\n", scary_length(a)); //=> 2
You can push elements with automatic memory extension,
as much as you want.

Moreover, the `scary_push` is a _generic_ function, so this code

```c
scary_push(&a, 0UL); // Pushing `unsigned long` into an array of `int`!
```
produces a warning by default with modern compilers like GCC 12.a
<pre><code><b>warning:</b> passing argument 1 of ‘scary_push_uint64’ from incompatible pointer type [-Wincompatible-pointer-types]
scary_push(<b>&a</b>, 0UL);
<b>^~</b>
<b>|</b>
<b>int **</b>
</code></pre>
You can of course opt-in an option `-Werror` to prevent such typing mistakes.
And you'll see **magic** here:
```c
Expand Down
6 changes: 6 additions & 0 deletions testlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ Test(libscary, push_and_length) {
Test(libscary, push) {
int *a = scary_new(sizeof(int));
scary_push(&a, 42);
scary_push(&a, 0UL);
cr_expect(eq(sz, 1, scary_length(a)));

scary_free(a);

char *b = scary_new(sizeof(char));
Expand All @@ -32,6 +34,10 @@ Test(libscary, push) {
cr_expect(eq(sz, 2, scary_length(b)));
cr_expect(eq(chr, 'a', b[0]));
cr_expect(eq(chr, 'b', b[1]));




scary_free(b);
}

Expand Down

0 comments on commit 2cb603a

Please sign in to comment.