外文地址:http://www.unixwiz.net/techtips/gnu-c-attributes.html

__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 being reached. The C library functions abort() and exit() are
both declared with this attribute:

这个属性告诉编译器函数不会返回,这可以用来抑制关于未达到代码路径的错误。 C库函数abort()和exit()都使用此属性声明:

extern void exit(int)   __attribute__((noreturn));
extern void abort(void) __attribute__((noreturn));

Once tagged this way, the compiler can keep track of paths through the code and suppress errors that won't ever happen due to the flow of 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 compiler is correct here, because it has no way of knowing that control doesn'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 spurious warning:

$ cat test2.c
extern void exitnow() __attribute__((noreturn)); int foo(int n)
{
if ( n > 0 )
exitnow();
else
return 0;
} $ cc -c -Wall test2.c
no warnings!

__attribute__((noreturn))的用法的更多相关文章

  1. GUN C/C++ __attribute__ 用法 转

     http://blog.csdn.net/mydo/article/details/3738336     GNUC的一大特色(却不被初学者所知)就是__attribute__机制.__attrib ...

  2. iOS宏和__attribute__

    本文目录 iOS宏的经典用法 Apple的习惯 __attribute__ iOS宏的经典用法 1.常量宏.表达式宏 #define kTabBarH (49.0f) #define kScreenH ...

  3. __attribute__

    转来的: http://www.cnblogs.com/astwish/p/3460618.html __attribute__ 你知多少? GNU C 的一大特色就是__attribute__ 机制 ...

  4. __attribute__ 你知多少?

    GNU C 的一大特色就是__attribute__ 机制.__attribute__ 可以设置函数属性(Function Attribute ).变量属性(Variable Attribute )和 ...

  5. __ATTRIBUTE__ 你知多少?【转】

    转自:http://www.cnblogs.com/astwish/p/3460618.html GNU C 的一大特色就是__attribute__ 机制.__attribute__ 可以设置函数属 ...

  6. __attribute__你知多少(转)

    转自:http://www.cnblogs.com/astwish/p/3460618.html GNU C 的一大特色就是__attribute__ 机制.__attribute__ 可以设置函数属 ...

  7. C之attribute用法

    GNU C 的一大特色就是__attribute__ 机制.__attribute__ 可以设置函数属性(Function Attribute ).变量属性(Variable Attribute )和 ...

  8. __attribute__的一些相关属性

    __attribute__((format()))  这个format有3个参数. int my(NSString *str,NSString *str1,NSArray*str2,...) __at ...

  9. __ATTRIBUTE__ 知多少?

    GNU C 的一大特色就是__attribute__ 机制.__attribute__ 可以设置函数属性(Function Attribute ).变量属性(Variable Attribute )和 ...

随机推荐

  1. 怎样制作gif图片?怎样制作你项目的动态效果图到你的csdn?

    怎样制作gif图?怎样上传你项目的动态效果图到你的csdn? 这仅仅是笔者用的方法.有其它方法的欢迎分享. 一张或几张展示了你的项目的功能及效果的动态图放在博客文章开头会为你的文章润色不少. 相信非常 ...

  2. react-redux的connect()方法

    容器组件使用 connect() 方法连接 Redux 我们用 react-redux 提供的 connect() 方法将“笨拙”的 Counter 转化成容器组件.connect() 允许你从 Re ...

  3. python(28)- 面向对象练习Ⅱ

    题目一:总结 1.什么是绑定到对象的方法,如何定义,如何调用,给谁用?有什么特性? 类内定义的函数,不经装饰器装饰,被实例化对象调用,会默认传入一个self参数,对象将会传递给self: 定义方式比较 ...

  4. 对OpenCV中Haar特征CvHaarClassifierCascade等结构理解

    首先说一下这个级联分类器,OpenCV中级联分类器是根据VJ 04年的那篇论文(Robust Real-Time Face Detection)编写的,查看那篇论文,知道构建分类器的步骤如下: 1.根 ...

  5. 斯坦福公开课:Developing IOS 8 App with Swift(1-3)心得体会

    最近开始学习Swift开发移动程序.跟随斯坦福大学的公开课进行自学. 这真是一个美好的时代,虽然不能在斯坦福求学,但是可以观看录制的授课录像.讲义,好似老师在给我们上课一样! 心得: 1.每节课信息量 ...

  6. iOS移动开发周报-第17期

    lhq iOS移动开发周报-第17期 前言 欢迎国内的iOS同行或技术作者向我提交周报线索,线索可以是新闻.教程.开发工具或开源项目,将相关文章的简介和链接在微博上发布并 @唐巧_boy 即可. [摘 ...

  7. PHP debug_backtrace() 函数

    PHP Error 和 Logging 函数 实例 生成 PHP backtrace: <?php function a($txt) { b("Glenn"); } func ...

  8. hdu1028(母函数+DP)

    题目信息:求分解整数n的个数q(n);能够母函数或者DP http://acm.hdu.edu.cn/showproblem.php?pid=1028 AC代码: /***************** ...

  9. spring+mybatis多数据源,动态切换

    有时我们项目中需要配置多个数据源,不同的业务使用的数据库不同 实现思路:配置多个dataSource ,再配置多个sqlSessionFactory,和dataSource一一对应.重写SqlSess ...

  10. Java基础知识查漏 一

    Java基础知识查漏 一 Jdk和jre Jdk是java程序设计师的开发工具,只要包含编译程序,jvm和java函数库 Jre中只有jvm和java函数库,没有编译程序的相关工具,适合只运行不撰写j ...