Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 45e8c0a2 authored by Sharvil Nanavati's avatar Sharvil Nanavati Committed by Andre Eisenbach
Browse files

Add a section on assertions to the style guide.

Change-Id: I5627b5b2d6b25f0472c53b8150b14bab79b200c3
parent 774d5fe1
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -168,6 +168,25 @@ routines and objects returned from those functions must be freed with the
corresponding `*_free` function. For example, list objects returned from
`list_new` should be freed with `list_free` and no other freeing routine.

### Asserts
Use `assert` liberally throughout the code to enforce invariants. Assertions
should not have any side-effects and should be used to detect programming logic
errors.

At minimum, every function should assert expectations on its arguments. The
following example demonstrates the kinds of assertions one should make on
function arguments.
```
  size_t open_and_read_file(const char *filename, void *target_buffer, size_t max_bytes) {
    assert(filename != NULL);
    assert(filename[0] != '\0');
    assert(target_buffer != NULL);
    assert(max_bytes > 0);

    // function implementation begins here
  }
```

## Header files
In general, every source file (`.c` or `.cpp`) in a `src/` directory should
have a corresponding header (`.h`) in the `include/` directory.