Skip to content

Commit 0b01fa0

Browse files
committed
core/compiler_hints: Add NONSTRING attribute
This adds the `NONSTRING` attribute that is defined as either `__attribute__((nonstring))` or as empty, depending on whether the toolchain understands the `nonstring` attribute. This allows declaring char arrays as not being a zero-terminated c-string without cluttering the code with preprocessor conditinational to ensure backward compatibility with compilers that do not support `-Wunterminated-string-initialization` yet.
1 parent 914429c commit 0b01fa0

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

core/lib/include/compiler_hints.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,20 @@ extern "C" {
4040
# endif
4141
#endif
4242

43+
/**
44+
* @def NONSTRING
45+
* @brief The `NONSTRING` keyword tells the compiler to assume that a char array
46+
* is not used as c string. (Specifically: It does not need a terminating
47+
* zero byte.)
48+
*/
49+
#ifndef NONSTRING
50+
# if (__GNUC__ >= 15)
51+
# define NONSTRING __attribute__((nonstring))
52+
# else
53+
# define NONSTRING
54+
# endif
55+
#endif
56+
4357
/**
4458
* @def PURE
4559
* @brief The function has no effects except the return value and its return

0 commit comments

Comments
 (0)