消除警告函数前面加上__ attribute__((unused)) #include <stdio.h> int main() { printf("main\n"); return 0; } __attribute__((unused))static void a(void) { printf("a\n"); } noreturn __ attribute__((noreturn)):这个属性告诉编译器函数永远不会有返回值,可以避免当一个函数需要返回值...
unused:告诉编译器该变量或函数未被使用,避免编译器产生警告。 noreturn:告诉编译器该函数不会返回,避免编译器产生警告。 format:指定函数的参数格式,用于检查printf和scanf等函数的参数类型。 constructor: 指定函数为构造函数,在程序启动时自动执行。 destructor:指定函数为析构函数,在程序结束时自动执行__attribute__...
__attribute__ ((attribute-list)) 1 三、指定函数的属性 参看:GNU 声明函数的属性 在GNU C 中,您声明有关程序中调用的函数的某些内容,这有助于编译器优化函数调用并更仔细地检查您的代码。 以下属性目前在所有目标函数的定义: aligned, alloc_size, noreturn, returns_twice, noinline, noclone, always_inli...
/* 把类似printf的消息传递给stderr 并退出 */extern void die(const char *format, ...) __attribute__((noreturn)) __attribute__((format(printf, 1, 2))); 或者写成 extern void die(const char *format, ...) __attribute__((noreturn, format(printf, 1, 2))); 如果带有该属性的自定义...
当__attribute__ 用于修饰对象时,它就如同C 语言语法体系结构的类型限定符,跟const, volatile , restrict 等属一类。 当__attribute__ 用于修饰函数时,它就相当于一个函数说明符,跟inline,Noreturn 属同一类。 当__attribute_ 用于修饰一个结构体,联合体或者枚举类型,该限定符只能放在类型标识符之前。
在C语言中,__attribute__((noreturn))的用途是什么? __attribute__ ((packed)) 的作用就是告诉编译器取消结构在编译过程中的优化对齐,按照实际占用字节数进行对齐,是GCC特有的语法。这个功能是跟操作系统没关系,跟编译器有关 。 __attribute__((aligned(4)));设置4字节对齐方式,和#pragma pack(4) 效果一...
noreturn:用于标记函数永远不会返回。例如,在函数中调用了exit函数,它是一个不返回的函数。 void myExit() __attribute__((noreturn)); void myExit() { // Function body exit(0); } 复制代码 deprecated:用于标记函数已被弃用,不推荐使用。这在API升级或替代旧函数时非常有用。 int oldFunction() __...
extern void exit(int) __attribute__((noreturn)); extern void abort(void) __attribute__((noreturn)); 为了方便理解,大家可以参考如下的例子: //name: noreturn.c ;测试__attribute__((noreturn)) extern void myexit(); int test(int n) ...
knows this automatically. Some programs define their own functions that neverreturn. You can declare themnoreturnto tell the compiler this fact. For example,voidfatal()__attribute__((noreturn));voidfatal(/* . . . */){/* . . . *//* Print error message. *//* . . . */exit(1);...