|
-
January 18th, 2013, 09:26 AM
#4
Re: Spliting bytes
A union is a pretty normal way to address individual bytes of a larger structure. Getting the individual bytes with the macro's victor posted is equally common.
When done right, neither of the two has an appreciable performance penalty or benefit to the other.
In this particular case, you could also have used an RGBQUAD structure (available in the windows API) instead of the array of 4 chars. (assuming the bytes are in the same order as in the RGBQUAD). Or you could even have added the RGBQUAD as a 3rd choice of accessing the union.
Depending on how you access the data from your C/C++ code, either of the solutions may have benefits in either ease of coding or readability.
Here, a union "makes more sense" than the macro's. But sometimes the macro's "make more sense" than a union would.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|