我手里有一些 c++ 项目,在这个问题出现之前,我在尝试 c++20 之后的 makefile 中有 c++17 标志,这个警告出现了。
看了一小会后,我不明白问题出在哪里,在 C++20 标记后,这是我从编译器得到的;
main.cpp: In function 'void heartbeat(LPHEART, int)':
main.cpp:185:20: warning: compound assignment with 'volatile'-qualified left operand is deprecated [-Wvolatile]
这是警告的代码原因;
volatile int num_events_called = 0;
void heartbeat (LPHEART ht, int pulse)
{
DWORD t;
t = get_dword_time();
num_events_called += event_process (pulse); // LINE 185 IS HERE <<<<<
s_dwProfiler[PROF_EVENT] += (get_dword_time() - t);
t = get_dword_time();
if (!(pulse % ht->passes_per_sec))
{
if (!g_bAuthServer)
{
TPlayerCountPacket pack;
pack.dwCount = DESC_MANAGER::instance().GetLocalUserCount();
db_clientdesc->DBPacket(HEADER_GD_PLAYER_COUNT, 0, &pack, sizeof(TPlayerCountPacket));
}
else
{
DESC_MANAGER::instance().ProcessExpiredLoginKey();
}
{
int count = 0;
if (save_idx < g_vec_save.size())
{
count = MIN(100, g_vec_save.size() - save_idx);
for (int i = 0; i < count; ++i, ++save_idx)
db_clientdesc->DBPacket(HEADER_GD_PLAYER_SAVE, 0, &g_vec_save[save_idx], sizeof(TPlayerTable));
sys_log(0, "SAVE_FLUSH %d", count);
}
}
}
if (!(pulse % (passes_per_sec + 4)))
CHARACTER_MANAGER::instance().ProcessDelayedSave();
if (!(pulse % (passes_per_sec * 5 + 2)))
{
ITEM_MANAGER::instance().Update();
DESC_MANAGER::instance().UpdateLocalUserCount();
}
s_dwProfiler[PROF_HEARTBEAT] += (get_dword_time() - t);
DBManager::instance().Process();
AccountDB::instance().Process();
CPVPManager::instance().Process();
if (g_bShutdown)
{
if (thecore_pulse() > g_shutdown_disconnect_pulse)
{
const DESC_MANAGER::DESC_SET & c_set_desc = DESC_MANAGER::instance().GetClientSet();
std::for_each(c_set_desc.begin(), c_set_desc.end(), ::SendDisconnectFunc());
g_shutdown_disconnect_pulse = INT_MAX;
}
else if (thecore_pulse() > g_shutdown_disconnect_force_pulse)
{
const DESC_MANAGER::DESC_SET & c_set_desc = DESC_MANAGER::instance().GetClientSet();
std::for_each(c_set_desc.begin(), c_set_desc.end(), ::DisconnectFunc());
}
else if (thecore_pulse() > g_shutdown_disconnect_force_pulse + PASSES_PER_SEC(5))
{
thecore_shutdown();
}
}
}
我应该怎么做才能击败这个警告?此致。