The unused
and noreturn
function attributes are listed in the section Common Function Attributes in the GCC manual. This means that they are supported by GCC on every platform, unless otherwise specified. (Or at least, the maintainers intend it to be supported; bugs are always possible.) Attributes that are specific to particular target platforms are listed instead in separate sections, e.g. AArch64 Function Attributes, MIPS Function Attributes.
Moreover, for unused
and noreturn
in particular, they are purely compile-time features, affecting only the warnings and/or optimizations done by the compiler. There is nothing about them that would seem platform-dependent, and they are presumably implemented in the generic portion of the compiler that is independent of platform. So it makes sense that they would work on all platforms.
clang's documentation is less complete, but generally, they aim to provide all of GCC's extensions, except where noted otherwise. And unused/noreturn
are very mature features, supported at least as far back as GCC 2.6.3 circa 1994, several years before the LLVM project was even begun. So I think it's safe to assume that clang supports them. And it presumably supports them across all platforms, because there is no reason for it not to. If you found an instance where it wasn't, I'd consider it a clang bug that should be reported.
Of course, you would want to actually test on each platform that your program is advertised as supporting.
It probably goes without saying, but I don't know of any compilers other than GCC and clang that support the __attribute__
syntax at all. It is not part of ISO standard C.
However, ISO C from C23 onward specifies the [[..]]
syntax for attributes, and includes standard attributes [[noreturn]]
and [[maybe_unused]]
. As GCC and clang both aim for ISO C compliance, they should support this standard syntax as well (you might have to use --std=c2x
or --std=c23
), and so will every other C23 compilant compiler. So moving forward, you will probably want to switch your code to use the ISO syntax.
__attribute__
. Always check the compiler documentation whenever you see anything beginning with an underscore.__attribute__
in all cases? @Someprogrammerdude. I specifically meant portable acrossgcc
andclang
.