V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  wjx0912  ›  全部回复第 14 页 / 共 37 页
回复总数  724
1 ... 10  11  12  13  14  15  16  17  18  19 ... 37  
@ysc3839 谢谢
@zpd2009 谢谢。还是运行时没完全理解。但这种坑对新手实在是不友好
@Shatyuka windows 的 DllMain.DLL_PROCESS_ATTACH 执行的比较晚,所以不会有这个问题,对吧
@Shatyuka 正解。谢谢
@chingyat 嗯。这个是没问题的。但是 g_test 不是固定值(会从文本读取)。runtime 执行一堆 constructor 的顺序问题。
这个不是编译器 bug ,是未指定行为
```
搞定了,把:
std::string g_test1;
std::string g_test2;
改成:
__attribute__((init_priority(101))) std::string g_test1;
__attribute__((init_priority(101))) std::string g_test2;

参考:
https://stackoverflow.com/questions/43941159/global-static-variables-initialization-issue-with-attribute-constructor-i
```
猜测的原因:__attribute__((constructor))时,c++ runtime 还未初始化,std::string 的一些操作可能不稳定。

测试:
```
std::string g_test1;
std::string g_test2;

__attribute__((constructor))
static void init() {
g_test1 = "hello test1";
printf("init: %s\n", g_test1.c_str());
}

void hello_func1(void) {
g_test2 = "hello test2";
printf("Hello World: %s, %s\n", g_test1.c_str(), g_test2.c_str());

return;
}

void hello_func2(void) {
printf("Hello World: %s, %s\n", g_test1.c_str(), g_test2.c_str());

return;
}
```

在 hello_func2 里面,g_test1 无法打印,g_test2 正常。

不知道这个思路是否正确,求大神指点
不缺那一百块的话,13600KF -> 13600K
你这 hr 的 kpi 不给满分委屈了,直接写邮件,让老板给他加工资
308 天前
回复了 aguaiabcdef 创建的主题 程序员 想装个台式机,希望各位给点意见
内存太小了。我 10700 黑苹果都配了 64g
厉害了
上面的软件全试了一遍,tabby cat 比较好用
311 天前
回复了 liuchengfeng1 创建的主题 程序员 成都 3 年多 Vuer 前端求坑位~
感觉不错。只是简历太长看的累。18-25k 没问题
楼主得说下什么项目,特定场景还是终端用户。如果对接的资源稀缺难搞,别说占 8 ,占 10 都合理
要怎么平常心面对互联网上一茬又一茬更年轻更优秀的年轻人呢?
改成:
要怎么不学习不进步面对互联网上一茬又一茬更年轻更优秀的年轻人呢?
@RiESA 就是太麻烦啊。每星期节省 5 分钟撸代码它不香吗
界面做的不错
316 天前
回复了 v2exosawa 创建的主题 优惠信息 腾讯云服务器活动, 3 年 388, 2+2+4
@HL8 一台自用。没有多的
1 ... 10  11  12  13  14  15  16  17  18  19 ... 37  
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5873 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 41ms · UTC 03:36 · PVG 11:36 · LAX 20:36 · JFK 23:36
Developed with CodeLauncher
♥ Do have faith in what you're doing.