From 40720a53c81073bb805386565317ac9f1cf8ac2d Mon Sep 17 00:00:00 2001 From: Quinn Date: Sat, 12 Apr 2025 20:27:55 +0200 Subject: [PATCH] write attributes in a header for ease of use this handles different compilers automatically and just provides a common method of using the attributes. Plus, it's less characters! --- src/util/atrb.h | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/util/atrb.h diff --git a/src/util/atrb.h b/src/util/atrb.h new file mode 100644 index 0000000..dba83a7 --- /dev/null +++ b/src/util/atrb.h @@ -0,0 +1,49 @@ +#pragma once + + +// default attribute definitions (empty) +#define atrb_deprecated +#define atrb_unused +#define atrb_pure +#define atrb_const +#define atrb_format() +#define atrb_nonnull() + +// define the attributes where possible +#if defined(__GNUC__) || defined(__clang__) + +# if __has_attribute(deprecated) +# undef atrb_deprecated +# define atrb_deprecated __attribute__((deprecated)) +# endif + +# if __has_attribute(unused) +# undef atrb_unused +# define atrb_unused __attribute__((unused)) +# endif + +# if __has_attribute(pure) +# undef atrb_pure +# define atrb_pure __attribute__((pure)) +# endif + + +# if __has_attribute(const) +# undef atrb_const +# define atrb_const __attribute__((const)) +# endif + +# if __has_attribute(format) +# undef atrb_format +# define atrb_format(...) __attribute__((format(__VA_ARGS__))) +# endif + +# if __has_attribute(nonnull) +# undef atrb_nonnull +# define atrb_nonnull(...) __attribute__((nonnull(__VA_ARGS__))) +# endif +#elif defined(_MSC_VER) +# undef atrb_depatrb_deprecated +# define atrb_deprecated __declspec(deprecated) +#endif +