Author Topic: using llu instead of d for the Format  (Read 4303 times)

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
using llu instead of d for the Format
« on: October 30, 2022, 06:45:46 am »
I see an alert message when C::B start in the latest rev 12996.

This patch try to fix it.

Code
From 63c1c31529667c9985c4ab96087ef1bf591f0e70 Mon Sep 17 00:00:00 2001
From: asmwarrior <a@b.com>
Date: Sun, 30 Oct 2022 13:39:30 +0800
Subject: use the %llu for unsigned long long value, otherwise, an alert will
 happen


diff --git a/src/sdk/toolsmanager.cpp b/src/sdk/toolsmanager.cpp
index 616fb2d1..ac6395bf 100644
--- a/src/sdk/toolsmanager.cpp
+++ b/src/sdk/toolsmanager.cpp
@@ -264,7 +264,7 @@ void ToolsManager::LoadTools()
 
         AddTool(&tool, false);
     }
-    Manager::Get()->GetLogManager()->Log(wxString::Format(_("Configured %d tools"), m_Tools.GetCount()));
+    Manager::Get()->GetLogManager()->Log(wxString::Format(_("Configured %llu tools"), m_Tools.GetCount()));
 }
 
 void ToolsManager::SaveTools()


My question is: why the old F() function does not show the alert message box?
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1553
Re: using llu instead of d for the Format
« Reply #1 on: October 30, 2022, 09:39:19 am »
This a diagnostic from the compiler (or wxWidgets), it knows how printf() works but nothing about F().

I did not see this because I am working with 32 bits, I will fix it in trunk.

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1553
Re: using llu instead of d for the Format
« Reply #2 on: October 30, 2022, 09:51:40 am »
Fixed in r12997.

Offline PB

  • Multiple posting newcomer
  • *
  • Posts: 57
Re: using llu instead of d for the Format
« Reply #3 on: October 30, 2022, 04:45:25 pm »
Fixed in r12997.

Just a nitpick, sorry. IMO, the correct solution would be to use "%zu". %zu is the natural formatter for size_t returned by GetCount() / size() methods of std(-like) containers,  hence no cast is required and the formatter works regardless of 32/64-bit builds. It has been supported by wxWidgets since a long time.

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1553
Re: using llu instead of d for the Format
« Reply #4 on: October 30, 2022, 06:24:58 pm »
Corrected in r12998, thank you.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: using llu instead of d for the Format
« Reply #5 on: October 31, 2022, 06:26:00 am »
@PB, @Miguel Gimenez

Thanks.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.