Boost logo

Boost :

From: helmut.zeisel_at_[hidden]
Date: 2001-10-16 02:44:29

--- In boost_at_y..., Darin Adler <darin_at_b...> wrote:
> on 10/15/01 1:57 PM, williamkempf_at_h... at williamkempf_at_h...
> wrote:

> > ../src\once.cpp:61: warning: unsigned int format, DWORD arg (arg
> > ../src\once.cpp:61: warning: unsigned int format, pointer arg
> These are warning about values passed to a printf-family function
that do
> not match the format in the printf string.

std::ostringstream has been designed to avoid these problems.
Instead of

        char name[41];
        HANDLE mutex = CreateMutex(NULL, FALSE, name);

you could include <sstream> and use

        std::ostringstream name;
        name << "2AC1A572DB6944B0A65C38C4140AF2F4"
             << std::hex << GetCurrentProcessId()
             << &flag;
        HANDLE mutex = CreateMutex(NULL, FALSE, name.str().c_str());

This is type safe and avoids potential problems with buffer overflows;
in particular, it should also work on future windows version
were the return type of GetCurrentProcessId() might change

OTOH you have an additional dependecy on <sstream>
and a (negligible?) performance penalty
for the dynamic memory allocation in std::ostringstream.

For <sstream> and GCC 2.95,


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