Copyright (c) 2024, Leo Kuznetsov
https://en.wikipedia.org/wiki/Fenwick_tree
There is K&R C, ANSI C, C89, C99, C11, C18, C2x and there is "C as I like it".
There is language itself, preprocessor, ancient runtime, several bickering standardization committees corporate and open source flavors and plethora of coding styles (e.g. MISRA C).
I have chosen to stick to the "C as I like it" style because it pleases my eye as long as it does not offend wider audience too much. I am aware that it is not the most popular style. I listen to critics and I am willing to improve the code to make it more readable and more portable.
- '''if (foo) { bar(); }''' without putting the compound block at a l ine of its own might be considered less readable.
- using
enum {}
for constants is at mercy of compilerint
type bit width but at least it does not leak elements names into global scope as#define
does. - The code is not always suitable for 16 and 8 bit architectures some tweaks may be required.
#define CONSTANTS_IN_SHOUTING_ALL_CAPS
is a great tradition but not a requirement. As a person, who has first hand experience with FORTRAN in 1976, I beg to be excused for ALL_CAPS 'readability' requirements.#define null ((void*)0)
personally invented this decades before C++ nullptr was even discussed. It's mine and I will stick to it.- IMHO
countof()
should be part of the language and yes do pay attention to the fact that it should not be used on arrays decaying to pointers. assert(bool, "printf formatted message", argv)
is super easy to implement and super useful in debugging. If you don't like it#define assert(b, ...) assert(b)
as a good compromise.swear(bool, "printf formatted message", argv)
is release mode fail fast fatal assertion.