resizablelib icon indicating copy to clipboard operation
resizablelib copied to clipboard

Format and argument size in TRACE

Open irwir opened this issue 2 years ago • 2 comments

https://github.com/ppescher/resizablelib/blob/8d6a0364f2730fdcbc398ab7ff045de7889fc1f5/ResizableLib/ResizableComboBox.cpp#L62

In case of 64-bit platform handle is 8 bytes long, while X format expects 4 bytes for an unsigned value. At least zX format is required for size_t (or MS-specific I64X in 64-bit code). 8 bytes may need 16 hexadecimal digits, but output should not be truncated according to language standards.

Possibly the line should be changed and then commented out as all other TRACE macros in the library code. //TRACE("ComboLBox: 0x%08zX\n", pWnd->m_hWnd);

irwir avatar Aug 09 '23 19:08 irwir

Hi, it's not clear to me why you are proposing to use a format specifier for size_t although the type of the varible is different (HWND). Moreover, it looks like the "z" modifier is only available since VS2019. Maybe I should use PRIXPTR for more portability across different VS versions (I think HWND is actually a pointer to an opaque struct)?

ppescher avatar Sep 03 '23 11:09 ppescher

The latest standards have a few specific *ptr_t types, but pointers used to be treated as size_t values, and HWND is declared as a pointer. PRIXPTR looks good enough; only #include <inttypes.h> has to be added. This macro did not exist in VS 6.0, but it was VC98 only.

irwir avatar Sep 03 '23 13:09 irwir

https://github.com/ppescher/resizablelib/blob/25a89da6e15b0d97f2347947c747ce50e549a20c/ResizableLib/ResizableComboBox.cpp#L61 To define the macro, #include <inttypes.h> is necessary. String concatenation requires spaces around the macro: TRACE("ComboLBox: 0x%08" PRIXPTR "\n", pWnd->m_hWnd);

irwir avatar Aug 03 '24 22:08 irwir

The TRACE line was inactive previously. Should it stay commented out?

irwir avatar Aug 05 '24 14:08 irwir

It doesn't matter, it's only active in debug builds. It can stay active, it was before I commented it out, waiting for me to decide what to do with the format specifier.

ppescher avatar Aug 05 '24 14:08 ppescher