
30 May
2008
30 May
'08
1:24 p.m.
On Fri, May 30, 2008 at 7:17 AM, Roman Perepelitsa
Scott McMurray
writes: std::copy( binary_buffer.begin(), binary_buffer.end(), reinterpret_cast
(&dr) ); Or: memcpy(&dr, &buffer[0], buffer.size());
Though a good implementation will have implemented std::copy for bytes with memcpy.
Or use union to avoid making a copy:
union { data d; unsigned char bytes[4]; } u;
bytes[0] = 3; bytes[1] = 6; bytes[2] = 0; bytes[3] = 9;
// use d.first, d.second, d.third
If your compiler allows that as an extension. (GCC does, dunno about others.) It's officially not allowed, last I checked.