One of the best (but little known) features of GNU C is the __attribute__ mechanism, which allows a developer to attach characteristics to function declarations to allow the compiler to perform more error checking. It was designed in a way to be compatible with non-GNU implementations, and we've been using this for years in highly portable code with very good results. Table of Contents __attribute__ format __attribute__ noreturn __attribute__ const Putting them together Compatibility with non-GNU compilers Other References Note that __attribute__ spelled with two underscores before and two after, and there are always two sets of parentheses surrounding the contents. There is a good reason for this - see below. Gnu CC needs to use the -Wall compiler directive to enable this (yes, there is a finer degree of warnings control available, but we are very big fans of max warnings anyway).
GNU C: __attribute__
最新推荐文章于 2023-07-03 00:04:28 发布
本文介绍了GNU C Compiler (GCC)中鲜为人知但极其强大的__attribute__机制。此特性允许开发者为函数声明附加特性,帮助编译器进行更严格的错误检查。文章详细探讨了__attribute__的格式及其具体用例,例如noreturn和const属性,并讨论了该机制如何与非GNU编译器兼容。
958

被折叠的 条评论
为什么被折叠?



