|
| 1 | +# Introduction {#mainpage} |
| 2 | + |
| 3 | +## What is Csnip? |
| 4 | + |
| 5 | +Csnip is a library of C code macros and functions (snippets, hence the |
| 6 | +name), that are frequently useful for general purpose C programming. |
| 7 | +It augments the standard C library with generic container data |
| 8 | +structures, such as dynamic arrays, lists, hash tables, and so on. It |
| 9 | +also provides high quality implementations of frequently used |
| 10 | +functionality such as for example random number generation. |
| 11 | + |
| 12 | +In short, it provides functionality similar to C++'s standard template |
| 13 | +library for C programs. |
| 14 | + |
| 15 | +## Csnip design goals |
| 16 | + |
| 17 | +We strive to provide components that are: |
| 18 | + |
| 19 | +- **Quality**. Csnip aims to provide higher quality algorithms and |
| 20 | + datastructures than what you would typically get if you implemented |
| 21 | + the same in an ad hoc fashion. |
| 22 | + |
| 23 | +- **Transparency**. The implementation of csnip's datastructures is |
| 24 | + documented in addition to the interfaces. You may opt to modify them |
| 25 | + directly; and in some cases this can come in handy, say, if you want |
| 26 | + to do something that's not possible or easy with the official |
| 27 | + interfaces. For example, you can use direct access to sample a random |
| 28 | + entry from a hash set, or can read data from a file into a dynamic |
| 29 | + array that way. |
| 30 | + |
| 31 | + In contrast, most other libraries are designed to be opaque, providing |
| 32 | + _data abstraction_ as a means to compartmentalize funcionality. In |
| 33 | + csnip, the same can be achieved with CSNIP\_\*\_{DECL,DEF}\_FUNCS() |
| 34 | + (see XXX), but it is entirely optional. It can be used when it makes |
| 35 | + sense, but avoided when it gets into the way. |
| 36 | + |
| 37 | +- **General**. Csnip wants to be useful for as wide a class of users |
| 38 | + and environments as possible. A liberal license is used so it can be |
| 39 | + used in as many contexts as possible. We try to stay portable where |
| 40 | + this is possible, but to provide the extras for environments that have |
| 41 | + them. Thus, e.g., type generic macros via \_Generic are used for C11 |
| 42 | + users along with non-generic versions for those which don't have that |
| 43 | + functionality available. |
| 44 | + |
| 45 | + Csnip is generic, thus e.g. the sorting functions do not depend on the |
| 46 | + data type being sorted, or what type of random access container is |
| 47 | + used to store the elements. |
| 48 | + |
| 49 | + We aim to design the library in a way that they can also be useful in |
| 50 | + uncommon use cases, provided that doesn't result in unduly burdening |
| 51 | + typical use cases. |
| 52 | + |
| 53 | +- **Pragmatic**. Csnip strives to be pragmatic. For example, we like |
| 54 | + consistent interfaces, but if they get in the way of e.g. usability, |
| 55 | + we'll do something else. Csnip tries to be general in the definition |
| 56 | + of its datastructures and function, but not to the point of making |
| 57 | + them unnecessarily painful. |
| 58 | + |
| 59 | +## Library conventions |
| 60 | + |
| 61 | +### Notation |
| 62 | + |
| 63 | +Csnip uses the prefixes csnip\_ or CSNIP\_ for its symbols and macros. |
| 64 | +Users should not define their own symbols or macros with such names. |
| 65 | + |
| 66 | +Many functions or macros are grouped by functionality, e.g. things |
| 67 | +related to memory management are called csnip\_mem\_\*. Though some very |
| 68 | +frequently used functionality that does not nicely fit into a group is |
| 69 | +directly under csnip\_\*, without further grouping. |
| 70 | + |
| 71 | +Macros that expand to statements or expression (_statement macros_ or |
| 72 | +_expression macros_) have upper CamelCase names; thus for example |
| 73 | +csnip\_arr\_Init() is a macro. Unless the behavior of the macro is |
| 74 | +documented for the case when the argument has side effects, the user is |
| 75 | +expected to use arguments without side effects, since the arguments may |
| 76 | +be evaluated more than once. |
| 77 | + |
| 78 | +Macros and enumeration values that expand to constants are all-caps |
| 79 | +after the prefix, e.g. csnip\_err\_SUCCESS is such a constant. |
| 80 | + |
| 81 | +Macros that evaluate to more than an expression or a statement are |
| 82 | +written in all-caps. Examples include macros that generate functions for |
| 83 | +container manipulation, such as CSNIP\_LPHASH\_TABLE\_DEF\_FUNCS(). |
| 84 | + |
| 85 | +Normal C functions and variables are written in snake case, for example |
| 86 | +csnip\_time\_timespec\_as\_float() is a function. |
| 87 | + |
0 commit comments