ppescher / resizablelib

A set of MFC classes to easily make resizable windows
Other
55 stars 27 forks source link

Format and argument size in TRACE #29

Open irwir opened 10 months ago

irwir commented 10 months ago

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);

ppescher commented 10 months ago

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)?

irwir commented 10 months ago

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.