[STM32F4] Map<uint64_t, shared_ptr<CLASS>>,begin() 返回 NULL

[复制链接]
石榴大王 发表于 2025-8-19 14:16 | 显示全部楼层 |阅读模式

空的 Map<uint64_t, shared_ptr<CLASS>>,begin() 返回 NULL。我的代码因为非法访问导致 HARD-HANDLE 错误,最终追踪到我的 MAP 上。

代码中有一个 shared_ptr 的 map,定义为 uint64_t。

在添加任何元素之前遍历元素会导致崩溃。

现在我发现,在空 map 上调用 .begin() 返回 NULL,

这个 MAP 看起来创建正确,left 和 right 都设置为 "END"。

但使用 begin() 时,仍然返回 NULL。

更奇怪的是……如果我用 uint32_t 作定义……它就正常了 :tired_face:,begin 和 end 都返回 "end"。

以下是简化版的普通 C++ 代码:

在我的 STM32 上的运行结果是:

it32_1 : 0x24004700

it32_2 : 0x24004700

it64_1 : 0x0

it64_2 : 0x240046e5

cpp.sh/8mruw

// map::begin/end
#include <iostream>
#include <map>
#include <memory>

class test
{
public:
test(){};
~test(){};
};

int main ()
{
std::map<uint32_t, std::shared_ptr<test>> testMap32;
std::map<uint64_t, std::shared_ptr<test>> testMap64;

auto it32_1 = testMap32.begin();
auto it32_2 = testMap32.end();

auto it64_1 = testMap64.begin();
auto it64_2 = testMap64.end();

printf("it32_1 : %p\r\n",it32_1);
printf("it32_2 : %p\r\n",it32_2);

printf("it64_1 : %p\r\n",it64_1);
printf("it64_2 : %p\r\n",it64_2);

return 0;
}
这是编译器的 BUG 吗???

我已经更新到 IDE 1.7。

同时试过以下类型:

uint8_t 失败

uint16_t 成功

qintian0303 发表于 2025-8-19 15:26 | 显示全部楼层
问题是你这用的什么IDE啊,正常的C语言中不支持uint64_t吧  
您需要登录后才可以回帖 登录 | 注册

本版积分规则

40

主题

40

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部