https://github.com/tadd/libscary
A (scary) scalable array library in C
https://github.com/tadd/libscary
array c-library scary
Last synced: 11 months ago
JSON representation
A (scary) scalable array library in C
- Host: GitHub
- URL: https://github.com/tadd/libscary
- Owner: tadd
- Created: 2024-09-20T12:00:15.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-05-24T15:06:13.000Z (about 1 year ago)
- Last Synced: 2025-05-24T16:28:53.244Z (about 1 year ago)
- Topics: array, c-library, scary
- Language: C
- Homepage: https://github.com/tadd/libscary
- Size: 18.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
libscary: A (scary) scalable array library in C
===============================================
This is one of those rotten dynamic array libraries, but wait, just take a look.
```c
int *a = scary_new(sizeof(int));
```
Look at this LHS; it looks like an ordinary C array, but
```c
printf("length: %zu\n", scary_length(a)); //=> 0
```
they know their length by themselves 😱.
```c
scary_push(&a, -1);
scary_push(&a, 42);
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` function is _generic_ 😱. If you put this code,
```c
scary_push(&a, 0UL); // Pushing `unsigned long` into an array of `int`!
```
it will produce a warning by default with modern compilers like GCC 12.
warning: passing argument 1 of 'scary_push_uint64' from incompatible pointer type [-Wincompatible-pointer-types]
scary_push(&a, 0UL);
^~
|
int **
You can of course opt-in an option `-Werror` to prevent such typing mistakes.
And you'll see **magic** here:
```c
int i = a[1];
```
You can read/write them as ordinary C arrays with **zero**-overhead 😱😱.
```c
printf("content: %d\n", i);
```
Then it prints `42`. Happy ending. 🤔🤔
## Usage
1. `make` and get `libscary.so`.
2. Write your code with `#include `.
3. Compile with `-lscary` and proper `-I`/`-L`.
4. Enjoy your looseness.
## Development
We use [Criterion](https://github.com/Snaipe/Criterion) for tests so
you'll need to install that before `make test`.
Dear Debian/Ubuntu users: You can install its package via
apt install [libcriterion-dev](https://packages.debian.org/stable/libcriterion-dev).
## License
[CC0](./CC0.md).