[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Bus error after casting (well defined) const unsigned char * to cons
From: |
Earl Purple |
Subject: |
Re: Bus error after casting (well defined) const unsigned char * to const double * |
Date: |
16 Aug 2006 09:15:18 -0700 |
User-agent: |
G2/0.2 |
Paul Pluzhnikov wrote:
> "Earl Purple" <earlpurple@gmail.com> writes:
>
> The buffer into which you received the data must not have been
> properly aligned.
>
> You have to either do that, or ensure that the data is properly
> aligned in the buffer. For example:
>
> union { char buf[200]; double d; } u;
> receive_data(u.buf, sizeof(buf));
> double *p = reinterpret_cast<double*>(u.buf); // OK
> p = &u.d; // same thing
Thank you. This was resolved also on comp.lang.moderated.c++. For those
who use boost they have a special template to do what you just did
above with the union.
(boost::aligned_data or something like that).