Sign in to follow this  
nuclear123

pointer help :D

Recommended Posts

nuclear123    119
DWORD X = 5; // X = 5 ; DWORD * Y = &X ; // Y = address of X DWORD copy = *Y ; // copy is now = 5 , dereferenced Y byte bytecopy = *(byte*)Y ; // point to the address of Y but only copy 8 bits instead of 4 bytes and get the value those 8 bits produce and store it in bytecopy? am i understanding the last statement correctly? byte bytecopy = *(byte*)Y ; // point to the address of Y but only copy 8 bits instead of 4 bytes and get the value those 8 bits produce and store it in bytecopy? c

Share this post


Link to post
Share on other sites
Ron AF Greve    900
Hi,

Well for instance in the following case. I have a serialization system in C++. At the lowest level when writing something to disk (whether string type, char * long etc. etc) it will write it as a sequence of bytes. So at the lowest level I do actually write every individual byte (okay I use it as a character buffer but the principal stays the same ).

stream.write( (char*)Buffer, sizeof( Type ) );

Now type can be any integer type (string needs some specialization, i.e. a separate function since it needs to store length and the character buffer in string).

So any data will eventually end up as a stream of characters.

However in my code I rarely dereference a single byte from a larger datatype. The above is one example, other examples might be working with colors where you have an ARGB layout and you need to convert to another layout like RGBA.

[Edited by - Ron AF Greve on February 7, 2010 9:30:45 AM]

Share this post


Link to post
Share on other sites
Mantear    251
You would need something like this if you need to serialize some object data into a byte stream for transfering across some external interface.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this