damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

README.md (3032B)


      1 A small library for adding C11 compatibility to older C compilers, but
      2 only a small highly useful subset such as static assertions, inline
      3 functions and alignment.
      4 
      5 C++ is not a primary target, but the library has been updated to be more
      6 C++ friendly based on user feedback.
      7 
      8 Many compilers already have the required functionality but with slightly
      9 different names and arguments.
     10 
     11 In addition, compatibility with the Linux `<endian.h>` system file is
     12 provided, and "punaligned.h" is provided for unaligned memory reads
     13 which in part depends on endian support.
     14 
     15 The library also provides fast integer printing and floating point
     16 printing and parsing optionally using the grisu3 algorithm, but can fall
     17 back to strtod and related. The `pgrisu3` folder is header only and
     18 excludes test cases found in the main grisu3 project the files were
     19 extracted from. Base64 conversion is also provided.
     20 
     21 Integer conversion is not just an optimization. It is more difficult
     22 than it would appear to portably parse an integer of known size such as
     23 `uint64_t` up to at most n bytes which is needed for safe parsing. At
     24 the same time, the sometimes significant performance gains warrants
     25 custom implementations that might as well be done once and for all.
     26 
     27 Files can be included individually, or portable.h may be included to get
     28 all functionality. If the compiler is C11 compliant, portable.h will not
     29 include anything, except: it will provide a patch for static assertions
     30 which clang does not fully support in all versions even with C11 flagged.
     31 
     32 The grisu3 header files are the runtime files for the Grisu3 floating
     33 point conversion to/from text C port. Test coverage is provided separately.
     34 This library can be used indirectly via pparsefp.h and pprintfp.h.
     35 
     36 The `pstatic_assert.h` file is often needed on C11 systems because the
     37 compiler and standard library  may support `_Static_assert` without
     38 `static_assert`. For compilers without `_Static_assert`, a unique
     39 identifier is needed for each assertion. This is done non-standard with
     40 the `__COUNTER__` macro, but has a fallback to `pstatic_assert_scope.h`
     41 for systems witout the `__COUNTER__` macro. Because of this fallback,
     42 `pstatic_assert.h` needs to be included in every file using
     43 `static_assert` in order to increment a scope counter, otherwise there
     44 is a risk of assert identifier conflicts when `static_assert` happen on
     45 the same line in different files.
     46 
     47 The `paligned_alloc.h` file implements the non-standard `aligned_free`
     48 to match the C11 standard `aligned_alloc` call. `aligned_free`  is
     49 normally equivalent to `free`, but not on systems where `aligned_free`
     50 cannot be implemented using a system provived `free` call. Use of
     51 `aligned_free` is thus optional on some systems, but using it increases
     52 general portablity at the cost of pure C11 compatibility.
     53 
     54 IMPORTANT NOTE: this library has been used on various platforms and
     55 updated with user feedback but it is impossibly to systematically test
     56 all platforms so please test for specific uses cases and report
     57 any issues upstream.