栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

Linux C 模拟 constructor and destructor

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Linux C 模拟 constructor and destructor

Linux 复制粘贴 分为 缓冲区 和 系统剪贴板

1.缓冲区只能在本编辑内有效
2.系统剪贴板可以粘贴到外部


cat "content" | xclip -selection c 
复制到系统剪贴板,可以粘贴到外部!


设置段
.ctors
构造函数?
.dtors
析构函数?

#include
void my_init_0(){
	printf("init 0 OKn");
}
void my_init_1(){
	printf("init 1 OKn");
}
typedef void (*ctor_t)();


__attribute__((section(".ctors"))) 
ctor_t my_init_0_c = my_init_0;

__attribute__((section(".ctors"))) 
ctor_t my_init_1_c = my_init_1;



int main(){
	printf("main OKn");
	return 0;
}

void my_destroy_0(){
	printf("destroy 0 OKn");
}
void my_destroy_1(){
	printf("destroy 1 OKn");
}
typedef void (*dtor_t)();
__attribute__((section(".dtors"))) 
ctor_t  my_destroy_0_d = my_destroy_0;
__attribute__((section(".dtors"))) 
ctor_t  my_destroy_1_d = my_destroy_1;



>>$ ./a.out                                                            127 ⨯
init 1 OK
init 0 OK
main OK
destroy 0 OK
destroy 1 OK

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/289015.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号