__attribute__ noreturn
This attribute tells the compiler that the function won't ever return,and this can be used to suppress errors about code paths not beingreached. The C library functions abort() and exit()
extern void exit(int) __attribute__((noreturn)); extern void abort(void) __attribute__((noreturn));
Once tagged this way, the compiler can keep track of paths throughthe code and suppress errors that won't ever happen due to the flowof control never returning after the function call.
In this example, two nearly-identical C source files refer to an"exitnow()" function that never returns, but without the__attribute__ tag, the compiler issues a warning. The compileris correct here, because it has no way of knowing that controldoesn't return.
$ cat test1.c extern void exitnow(); int foo(int n) { if ( n > 0 ) { exitnow(); /* control never reaches this point */ } else return 0; } $ cc -c -Wall test1.c test1.c: In function `foo': test1.c:9: warning: this function may return with or without a value
But when we add __attribute__, the compiler suppresses the spuriouswarning:
$ cat test2.c extern void exitnow() __attribute__((noreturn)); int foo(int n) { if ( n > 0 ) exitnow(); else return 0; } $ cc -c -Wall test2.cno warnings!
参考:
http://www.unixwiz.net/techtips/gnu-c-attributes.html#noreturn