当前位置: 首页 > news >正文

__attribute__((constructor))

转自:https://blog.csdn.net/accumla/article/details/96161462

__attribute__((constructor)) 先于main()函数调用

__attribute__((destructor)) 在main()函数后调用

#include <stdio.h> #include <stdlib.h> static void before(void) __attribute__((constructor)); static void after(void) __attribute__((destructor)); static void before() { printf("before main\n"); } static void after(void) { printf("after main\n"); } int main() { printf("main\n"); return 0; }

运行结果:

补充:优先级

通过参数设置优先级关系

#include <stdio.h> #include <stdlib.h> static void before(void) __attribute__((constructor)); static void before3(void) __attribute__((constructor(103))); static void before2(void) __attribute__((constructor(102))); static void before1(void) __attribute__((constructor(101))); static void before2() { printf("before 102\n"); } static void before1() { printf("before 101\n"); } static void before3() { printf("before 103\n"); } static void before() { printf("before main\n"); } int main() { printf("main\n"); return 0; }

运行结果:

http://www.jsqmd.com/news/375388/

相关文章:

  • LLM创造力可以被度量吗?一个基于提示词变更的探索性实验
  • 786785678
  • 2026年软考高项信息系统项目管理师认证十大高通过率培训机构老师权威评测 - 资讯焦点
  • Java求职面试:从Spring Boot到微服务的技术问答
  • 2026年GEO公司哪家好?中国GEO服务商综合实力TOP10权威评测榜单 - 资讯焦点
  • 利用openaiagents框架开发天气助手
  • 1.12
  • 2026最新十大知名实木板品牌推荐榜!优质环保品质与高性价比源头厂家选择指南 - 品牌推荐2026
  • 完整教程:华为eNSP模拟器综合实验- ospf区域的作用和报文类型的关系解析
  • 终末地-别礼队伍的装备配置和养成建议--16
  • 别再写丑陋的 Shell 脚本了:用 Gum 给你的终端穿上“高定西装”
  • 题解:AWC 0004
  • 修复Discuz 迁移后页面全部变成“????”乱码的问题
  • 2026最新十大知名生态板品牌推荐榜!优质环保品质与高性价比源头厂家选择指南,适配全屋定制多场景 - 品牌推荐2026
  • 彻底搞懂 Event Loop:宏任务与微任务的执行顺序全解析
  • 输入烧烤店时段客流,自动调整食材准备量,减少浪费
  • 游记:GZ ICPC2025
  • 2026激光切管十大品牌实力排名(年度十强争霸榜) - 匠言榜单
  • WPS office和WPS pdf
  • 2026年2月宁波精装改造设计公司哪家强? - 疯一样的风
  • 重磅!大数据OLAP助力智慧安防建设的关键
  • P11960 [GESP202503 五级] 平均分配 贪心+模拟
  • CQ小六竞赛生寒假悠闲的一天~~
  • 【Docker基础篇】实用CLI命令指南:run/stop/exec/logs,日常开发高频使用不踩坑
  • AI原生应用领域持续学习:构建技术知识体系的秘诀
  • 2026年2月护资模拟考试app权威推荐,界面流畅刷题更稳定 - 品牌鉴赏师
  • 【Docker基础篇】从0到1写Dockerfile:FROM/COPY/CMD/ENTRYPOINT指令详解+Hello World实战
  • 大规模语言模型的反事实推理与情景模拟
  • 2026最新十大知名全屋定制板材品牌推荐榜!优质环保品质与高性价比源头厂家选择指南,环保耐用适配多场景 - 品牌推荐2026
  • Elasticsearch 与 Cassandra 集成:处理超大规模数据