我是靠谱客的博主 昏睡含羞草,最近开发中收集的这篇文章主要介绍__attribute__ 介绍1、__attribute__((noreturn)),觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

__attribute__ 可以设置函数属性(Function Attribute )、变量属性(Variable Attribute )和类型属性(Type Attribute )。

1、__attribute__((noreturn))

该属性通知编译器函数从不返回值,当遇到类似函数需要返回值而却不可能运行到返回值处就已经退出来的情况,该属性可以避免出现错误信息。

注:测试可以返回void类型。

代码如下:

#include <stdio.h>

__attribute__((noreturn))

int func()
{
    printf("this is funcn");
    return 10;
}

void func1()
{
    printf("this is func1n");
    return (void)1;
}

void main()
{
    printf("main startn");
    printf("func1 startn");
    func1();
    printf("func startn");
    func();
    printf("main endn");
}

运行结果:

main start
func1 start
this is func1
func start
this is func

程序运行到fun函数return 10之前就退出整个程序了。

还有好多参数,涉及到在总结

最后

以上就是昏睡含羞草为你收集整理的__attribute__ 介绍1、__attribute__((noreturn))的全部内容,希望文章能够帮你解决__attribute__ 介绍1、__attribute__((noreturn))所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(67)

评论列表共有 0 条评论

立即
投稿
返回
顶部