[asio] static data member as buffer arg

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[asio] static data member as buffer arg

Jeff Flinn
Any obvious reason that supplying a static const data member to a buffer,
for example:

class Client
{
   static const unsigned int sHandShakeGreeting = 0x01020304;

   ba::stream_socket mSock;

   ...

   void SomeFnc()
   {
      ba::async_write( aSocket
                     , ba::buffer(&sHandShakeGreeting,4)
                     , boost::bind( &Client::OnSent, this, _1, _2 ) );
   }

   ...
};


would behave differently from:


const unsigned int sHandShakeGreeting = 0x01020304;

class Client
{

   ba::stream_socket mSock;

   ...

   void SomeFnc()
   {
      ba::async_write( aSocket
                     , ba::buffer(&sHandShakeGreeting,4)
                     , boost::bind( &Client::OnSent, this, _1, _2 ) );
   }

   ...
};

The above all occur within a .cpp file. In the latter case the dialog
continues as expected, but the former results in the server(I don't have
code for) not receiving a valid value. This is using VC7.1.

Thanks, Jeff



_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|

Re: [asio] static data member as buffer arg

Christopher Kohlhoff
Hi Jeff,

--- Jeff Flinn <[hidden email]> wrote:
> Any obvious reason that supplying a static const data member
> to a buffer, for example:
>
> class Client
> {
>    static const unsigned int sHandShakeGreeting = 0x01020304;
<snip>
>
> would behave differently from:
>
> const unsigned int sHandShakeGreeting = 0x01020304;
>
> class Client
> {
<snip>
> The above all occur within a .cpp file. In the latter case the
> dialog continues as expected, but the former results in the
> server(I don't have code for) not receiving a valid value.
> This is using VC7.1.

This smells like a compiler bug. Are you able to reproduce it in
a small program that sends data to an echo server, say?

Also, do you have a definition for the static outside the class?
i.e.:

  const unsigned int Client::sHandShakeGreeting;

Cheers,
Chris



_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost