Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Loading...
Searching...
No Matches
attributes.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015 Roc Streaming authors
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 */
8
9//! @file roc_core/attributes.h
10//! @brief Compiler attributes.
11
12#ifndef ROC_CORE_ATTRIBUTES_H_
13#define ROC_CORE_ATTRIBUTES_H_
14
15#include <hedley.h>
16
17//! Explicitly specify a default visibility for a specific symbol.
18#define ROC_ATTR_EXPORT HEDLEY_PUBLIC
19
20//! Declares that the return operator is not reachable.
21#define ROC_ATTR_UNREACHABLE_RETURN HEDLEY_UNREACHABLE_RETURN
22
23//! Function never returns.
24#define ROC_ATTR_NORETURN HEDLEY_NO_RETURN
25
26#ifdef HEDLEY_GCC_VERSION
27//! Emit warning if function result is not checked.
28#define ROC_ATTR_NODISCARD // GCC is too aggressive for this attribute.
29#else
30//! Emit warning if function result is not checked.
31#define ROC_ATTR_NODISCARD HEDLEY_WARN_UNUSED_RESULT
32#endif
33
34//! Function gets printf-like arguments.
35#define ROC_ATTR_PRINTF(fmt_pos, args_pos) HEDLEY_PRINTF_FORMAT(fmt_pos, args_pos)
36
37#if HEDLEY_HAS_ATTRIBUTE(unused)
38//! Function or variable is never used but no warning should be generated.
39#define ROC_ATTR_UNUSED __attribute__((unused))
40#else
41//! Function or variable is never used but no warning should be generated.
42#define ROC_ATTR_UNUSED
43#endif
44
45#if HEDLEY_HAS_ATTRIBUTE(packed)
46//! Pack structure fields.
47//! Place these before class or struct keyword.
48#define ROC_ATTR_PACKED_BEGIN
49//! Pack structure fields.
50//! Place these between '}' and ';'.
51#define ROC_ATTR_PACKED_END __attribute__((packed))
52#else
53//! Pack structure fields.
54//! Place these before class or struct keyword.
55#define ROC_ATTR_PACKED_BEGIN
56//! Pack structure fields.
57//! Place these between '}' and ';'.
58#define ROC_ATTR_PACKED_END
59#endif
60
61#if HEDLEY_HAS_ATTRIBUTE(aligned)
62//! The filed should have given alignment.
63#define ROC_ATTR_ALIGNED(x) __attribute__((aligned(x)))
64#endif
65
66#if HEDLEY_HAS_ATTRIBUTE(no_sanitize)
67//! Suppress undefined behavior sanitizer for a particular function.
68#define ROC_ATTR_NO_SANITIZE_UB __attribute__((no_sanitize("undefined")))
69#elif HEDLEY_HAS_ATTRIBUTE(no_sanitize_undefined)
70//! Suppress undefined behavior sanitizer for a particular function.
71#define ROC_ATTR_NO_SANITIZE_UB __attribute__((no_sanitize_undefined))
72#else
73//! Suppress undefined behavior sanitizer for a particular function.
74#define ROC_ATTR_NO_SANITIZE_UB
75#endif
76
77#endif // ROC_CORE_ATTRIBUTES_H_