Coder Social home page Coder Social logo

portable-snippets's Introduction

Portable Snippets

This is a collection of public domain (CC0) code snippets written in C for performing various common tasks which are typically OS, architecture, and/or compiler-dependent. Basically, our goal is to move those annoying preprocessor conditionals from your code to ours.

Modules have no fixed target (such as C89) since that would preclude some functionality; instead, we simply try to provide the widest support we can for each module. If you have a platform which isn't supported for a particular feature but could be, please let us know; we'd be happy to try to work out a way to support it.

Everything is tested continuously with various versions of GCC, Clang, and PGI (on Travis CI), MSVC (on AppVeyor), and Emscripten (on Codefresh):

Travis CI status AppVeyor status Codefresh status

Currently ready-to-use modules include:

  • builtin — use compiler built-ins/intrinsics, or fall back on standard C
  • endian — endianness detection and swapping
  • atomic — common atomic synchronization operations
  • safe-math — overflow-safe integer functions
  • exact-int — exact-width integer types (think <stdint.h>)
  • clock — cross-platform wall clock, CPU time, and monotonic time

There are also modules which may not yet be ready for widespread use, but would benefit greatly from testing:

  • unaligned — fast unaligned loads & stores
  • once — one-time initialization
  • random — random number generation (3 flavors: cryptographic, reproducible, and fast)
  • debug-trap — debugging traps and assertions
  • check — assertion checking

Modules can be used in isolation, though some do work better together, so if you can keep the whole repository together instead of just copying a single file we recommend you do so.

Please don't be shy about filing issues about any of these; if you have problems it's likely others will, as well, so we would like to fix them.

If you have something you would like to contribute, please file an issue or pull request. If you'd like to help out by writing something new, take a look at the "enhancement" issues in our issue tracker for ideas.

Some things don't really fit this repository, so here are a few small-ish projects for doing things portably which you may be interested in:

  • Hedley — macros to enable compiler-specific features which make your code easier to use, harder to misuse, safer, faster, and more portable.
  • parg — Argument parsing similar to getopt/getopt_long. Public domain.
  • TinyCThread — Implements the C11 threads API on top of pthreads and the Windows API. zlib license.
  • win-iconv — Windows implementation of the iconv API (character set conversion).
  • mman-win32mman.h (mmap(), etc.) implementation for Windows.

If there is a project you'd like to see added to the list, please file an issue or pull request.

portable-snippets's People

Contributors

karbyshev avatar nealrichardson avatar nemequ avatar pskocik avatar szakharchenko avatar tbeu avatar timgates42 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.