Boost logo

Boost :

From: Darin Adler (darin_at_[hidden])
Date: 2001-10-15 17:28:07

on 10/15/01 1:57 PM, williamkempf_at_[hidden] at williamkempf_at_[hidden]

> And, while I'm at it, there's a set of gcc warnings given when
> compiling with native Win32 threads that I could use some help on as
> well. Here's the output:
> gcc-C++-
> action ..\..\..\libs\thread\build\bin\libboost_thread\gcc\release\runt
> im
> e-link-dynamic\once.obj
> ../src\once.cpp: In function `void boost::call_once(void (*)(),
> once_flag &)':
> ../src\once.cpp:61: warning: unsigned int format, DWORD arg (arg 3)
> ../src\once.cpp:61: warning: unsigned int format, pointer arg (arg 4)

These are warning about values passed to a printf-family function that do
not match the format in the printf string.

The sprintf format string uses %X to print the result of
GetCurrentProcessId() and %X to print the result of &flag.

In the case of GetCurrentProcessId, the problem is that %X means an unsigned
integer, but DWORD is not the same as "unsigned int". The best fix is
probably to add a conversion to unsigned int -- I suggest doing it with
assignment to a local variable.

In the case of the pointer, you are trying to print the value of a pointer.
One way to do that is with the "%p" format string. But that's risky since I
don't know exactly how wide the string written by %p is, and it's important
not to overflow the fixed-size buffer you are passing in to sprintf. There
may be other ways of printing the pointer as a number that are more suitable
-- perhaps a reinterpret cast to unsigned.

    -- Darin

Boost list run by bdawes at, gregod at, cpdaniel at, john at