For context, I have a bitmapped field coming from a snmp reply that I can get from a printer. (panasonic workio DP-C264 - if anyone has technical documentation on it, I'd be glad to know!) I can information out of it with this line-

Code:

vb.get_value( (unsigned char *)&Job, Job_len, sizeof(snmpjoblog ));

where Job is an instance of a class containing the what ints and char arrays I have detected: there are a lot of char[n] unknowns and int unknowns.
I'd like to roll the function to extract that info into the class, which would mean this:

Code:

vb.get_value( (unsigned char *)this, Job_len, sizeof(snmpjoblog ));

As in, writing binary data over the top of the class itself. Now, when it compiled without error, I was suprised. But will this really work?
(I'm going to go try it with a utility I wrote, but I'd still like your input!)

__________________The only dumb question is a question not asked.
The only dumb answer is an answer not given.

I still cannot believe that this is a good thing - I mean, the class is overwriting itself!

From the information provided, the class is simply a repository for data (& the data is composed of fundamental types, no user-defined types...) -- no inheritance or virtual member functions are involved. Because of this scenario, this most likely points to the beginning of data, so the problem decomposes down to how one dumps/restores a struct. You may want to confirm this to yourself by looking at the address of this & compare to the address of the first member.

If the class structure involved inheritance, this would point to the vtable which would change from one instance of the application to the next. Writing to disk wouldn't be a problem, but restoring followed by calling any virtual member function (if present...) would most likely cause an exception. Depending upon the compiler used, accessing data from a restored object may be problematic as well.

The exact semantics of how & where the vtable is located in memory is compiler-dependent, so you would need to look further into your compiler's documentation or play with a debugger to confirm if you are interested.