0
点赞
收藏
分享

微信扫一扫

Ameya360:广和通发布新一代5G FWA解决方案

生活记录馆 2023-07-03 阅读 69

简介: CSDN博客专家,专注Android/Linux系统,分享多mic语音方案、音视频、编解码等技术,与大家一起成长!

优质专栏:Audio工程师进阶系列原创干货持续更新中……】🚀

人生格言: 人生从来没有捷径,只有行动才是治疗恐惧和懒惰的唯一良药.

更多原创,欢迎关注:Android系统攻城狮

欢迎关注Android系统攻城狮

1.前言

<1>.使用方式

注意:构造函数优先级从0100保留,所以使用100以上就可以了,使用100以下给出警告。
使用方式:
__attribute__((constructor(121))) static void test_02(){
  printf("xxx--------->%s, line = %d\n",__FUNCTION__,__LINE__);
}

__attribute__((constructor(103))) static void test_03(){
  printf("xxx--------->%s, line = %d\n",__FUNCTION__,__LINE__);
}

2.应用实例

#include <iostream>
using namespace std;

//1.test()在main函数之前调用,它是被系统调用,并非main函数调用.
__attribute__((constructor)) static void test(){
  printf("xxx--------->%s, line = %d\n",__FUNCTION__,__LINE__);
}

//2.test_01()在main函数之前调用,它是被系统调用,并非main函数调用.
__attribute__((constructor(103))) static void test_01(){//设置优先级为103
  printf("xxx--------->%s, line = %d\n",__FUNCTION__,__LINE__);
}

//3.test_02()在main函数之前调用,它是被系统调用,并非main函数调用.
__attribute__((constructor(101))) static void test_02(){//设置优先级为101
  printf("xxx--------->%s, line = %d\n",__FUNCTION__,__LINE__);
}

//4.test_03()被未调用,因为没有__attribute__((constructor))修饰.
void test_03(){
  printf("xxx--------->%s, line = %d\n",__FUNCTION__,__LINE__);
}

//4.__attribute__((destructor))修饰析构函数,在析构函数以后执行.
__attribute__((destructor)) void test_04(){
  printf("xxx--------->%s, line = %d\n",__FUNCTION__,__LINE__);
}

class A{
public :
  A(){
    printf("xxx--------->%s, line = %d\n",__FUNCTION__,__LINE__);
  }
  ~A(){
    printf("xxx--------->%s, line = %d\n",__FUNCTION__,__LINE__);
  }
};

int main() {
  A a;
  printf("xxx--------->%s, line = %d\n",__FUNCTION__,__LINE__);
  return 0;
}

举报

相关推荐

0 条评论