惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Threat Research - Cisco Blogs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
V
Vulnerabilities – Threatpost
GbyAI
GbyAI
P
Proofpoint News Feed
L
LINUX DO - 热门话题
P
Palo Alto Networks Blog
A
About on SuperTechFans
T
Tenable Blog
M
MIT News - Artificial intelligence
IT之家
IT之家
I
Intezer
D
DataBreaches.Net
爱范儿
爱范儿
T
Threatpost
C
CERT Recently Published Vulnerability Notes
云风的 BLOG
云风的 BLOG
博客园 - 三生石上(FineUI控件)
WordPress大学
WordPress大学
K
Kaspersky official blog
大猫的无限游戏
大猫的无限游戏
A
Arctic Wolf
Y
Y Combinator Blog
Cyberwarzone
Cyberwarzone
酷 壳 – CoolShell
酷 壳 – CoolShell
D
Darknet – Hacking Tools, Hacker News & Cyber Security
H
Help Net Security
Microsoft Security Blog
Microsoft Security Blog
Spread Privacy
Spread Privacy
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
AWS News Blog
AWS News Blog
博客园 - 聂微东
C
Check Point Blog
S
Securelist
有赞技术团队
有赞技术团队
雷峰网
雷峰网
aimingoo的专栏
aimingoo的专栏
Last Week in AI
Last Week in AI
Stack Overflow Blog
Stack Overflow Blog
MongoDB | Blog
MongoDB | Blog
D
Docker
G
GRAHAM CLULEY
T
The Exploit Database - CXSecurity.com
C
Cybersecurity and Infrastructure Security Agency CISA
T
Tailwind CSS Blog
L
Lohrmann on Cybersecurity
G
Google Developers Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
L
LangChain Blog

博客园 - James

Send-only Mail Server with Exim on Ubuntu 10.04 LTS Change hostname on Ubuntu without reboot 51IT最全的自动化测试工具QTP资料 QTP如何启动应用程序(转) - James - 博客园 找出用户表中有重复密码的用户 如何改变Linux Kennel中的shmmax参数 如何在Ubuntu上update gem for ruby 1.9.1的版本 google疯了 - James - 博客园 碰巧遇到一些智力面试题,解答一下 避免在电脑上浪费时间的好办法 如何在Postgresql中产生自己的集合function 用RJS写的检测用户名和email是否存在 ajax check username available in rails MSN Messager密码 - James - 博客园 重新开始Blog生活 准备用C#写一个Blog的客户端,大家看看功能缺哪些,哪些不需要? PInvoke 白话文 Apache 2 + PHP Windows安装指南(官方版本) .Text Blog .95中一个Unicode的bug - James
如何在C语言中使用constructor和destructor,gcc环境
James · 2010-06-02 · via 博客园 - James

使用这个功能,你就可以在main函数执行之前,和main函数退出之后,执行你自己想要的操作。具体原理,网上很多,自己google一下就找到了,这里只是给一个例子。

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 
 4 static void start(void) __attribute__ ((constructor));
 5 static void stop(void) __attribute__ ((destructor));
 6 
 7 int
 8 main(int argc, char *argv[])
 9 {
10         printf("start == %p\n", start);
11         printf("stop == %p\n", stop);
12 
13         exit(EXIT_SUCCESS);
14 }
15 
16 void
17 start(void)
18 {
19         printf("hello world!\n");
20 }
21 
22 void
23 stop(void)
24 {
25         printf("goodbye world!\n");
26 }
27 

运行结果:

hello world!

start == 0x4005fb

stop == 0x40060b

goodbye world!