Standard Library for C
All functions/variables/macros/structs have the prefix c_/C_ to them. If you know their won't be any name collisions if you remove them, you can do so by defining COMMONLIB_REMOVE_PREFIX before including the header like:
#define COMMONLIB_REMOVE_PREFIX
#include <commonlib.h>| C type | typedef |
|---|---|
| unsigned int | uint |
| uint8_t | uint8 |
| uint16_t | uint16 |
| uint32_t | uint32 |
| uint64_t | uint64 |
| int8_t | int8 |
| int16_t | int16 |
| int32_t | int32 |
| int64_t | int64 |
| float | float32 |
| double | float64 |
| wchar_t | wchar |
| const char* | cstr |
| const wchar* | wstr |
Dynamic array functions are implemented using macros and except a struct of your own with like:
typedef struct {
<item-type> *items;
size_t count;
size_t capacity;
[extra fields...];
}- c_darr_append(da, elm)
Appends the element
elmto the dynamic arrayda
- c_darr_shift(da)
Shifts the elements of the dynamic array
dato the left by one
Warning
c_darr_shift will make the da loose its ptr, so store the ptr elsewhere if you want to free it later!!!
- c_darr_delete(da, type, idx)
Deletes the element at index
idxfrom the dynamic arrayda;typeis needed because we swap the element with the last element in the array (SEE IMPLEMENTATION FOR MORE INFO).
- c_darr_remove(da, type, elm_ptr, idx)
Same as c_darr_delete() but user can provide a pointer
elm_ptrthat will be filled with the removed element.