Hedley is a single C/C++ header you can include in your project to enable compiler-specific features while retaining compatibility with all compilers. It contains dozens of macros to help make your code easier to use, harder to misuse, safer, faster, and more portable.
You can safely include Hedley in your public API, and it works with virtually any C or C++ compiler.
Learn how Hedley works, and how to make it work for you. Our easy-to-read user guide provides a gentle introduction to everything you need to know.
Detailed documentation of everything exposed by Hedley, including code samples, information on compiler support.
Partially for my own purposes; every time I created a project I found myself copying the same code into it, which certainly got old, and having to maintain twenty copies of the same thing is definitely not fun.
That said, the real reason is that I constantly noticed that other projects didn't do the same thing. They simply omitted the features that Hedley makes available… features which help improve security, stability, and performance. I want software I rely on to be safe, stable, and fast, even if I didn't write it.
Absolutely! Including multiple copies of Hedley will not cause a conflict. Just make sure the header is installed to a package-specific directory (e.g., /usr/include/your-library/hedley.h, not /usr/include/hedley.h). The User Guide explains everything in more detail.
CC0, which is basically an attempt to put it in the public domain, or as close as possible.
You can, but if you're exposing Hedley in your public API please change the namespace from HEDLEY to something else. If you don't it could cause problems for any other libraries which are using Hedley since your stripped-down version may not provide a macro someone else expects given the version of Hedley you claiming to support (by setting the value of HEDLEY_VERSION).
Maybe. The first rule is that if a feature isn't known
to be supported it must be safe to fall back on pure
C89. For example, it's not a big deal if the compiler
doesn't have an implementation
HEDLEY_INLINE; the macro is compiled
down to nothing and the function may not be inlined, but
that will not cause the code to stop functioning.
On the other hand, we can't add support for thread-local
storage because if the compiler doesn't support it and
we simply don't emit a TLS modifier
__declspec(thread), etc.) the behavior is
completely different and the resulting program will
almost certainly be broken.
If a feature isn't a good fit for Hedley it very well may be a good fit for Portable Snippets.
Macros defined by Hedley are safe to use anywhere; if a compiler isn't known to support a feature Hedley will simply output nothing, or standard C/C++, depending on what is appropriate. Think of Hedley as progressive enhancement for your code.
Compilers Hedley is able to take advantage of include:
Hedley makes use of varaidic macros for some functionality, and there is no way to define these away. Variadic macros have formally been part of C since C99, and part of C++ since C++11, but they have been available in virtually every compiler for much longer.
Even if you pass
-Wpedantic (or something
similar) to your compiler and you're in an older mode
(e.g., C89 or C++03), we can usually silence the warning
for you. The only time you're likely to run into an
issue is if your compiler is more than about 25 years
While better known as an actress, Hedy Lamarr was also an inventor (of, among other things, frequency-hopping spread spectrum radios).