Quote Originally Posted by matsp View Post
What problem are you actually trying to solve?
To exand what I said in the first post:
Code:
Header hdr;
read( reinterpret_cast<u_char*>(hdr) );
// Everything in it's right place now
// use hdr here
That means that the reinterpret_cast<u_char*>(hdr) would have to yield an array of unsigned chars to the read function, where the layout of the struct matches that of the expected array. Eg.
Code:
struct Header { u_char a; u_char b; } hdr;
// read, as above, expecting an array like: u_char arr[] = { 'a', 'b' };
hdr.a == 'a';
hdr.b == 'b';
From what everyone says, this is UB, so I'll have to do this another way. Gah.

However, just FYI, this part seems to work fine using MSVC8 and gcc 4.* on linux. On the other hand, when I try and create a structure like the one I decoded, MSVC seems to not like it and alters the struct in some way (I'm only 60% sure that's what's happening, since I haven't bothered looking at the assembly).