On Wed, 05 Jul 2006 20:58:29 -0500, Jack <> wrote:
>Is it possible to cast a 4-byte data type (e.g. an unsigned int) to a
>4-byte struct? Sometimes the HIWORD and LOWORD of a 4-byte value
>contain information independent of each other. Is there a direct way
>to perform this cast? If not, is there way in C++ to do it?
>
>For example, I would like my function test() to work the way it is
>coded below. It produces a compiler error though:
>
>#include <pshpack2.h> // 16-bit padding
>
>// My 4-byte struct
>typedef struct _mystruct_t
>{
> unsigned short cx;
> unsigned short cy;
>} mystruct_t;
>
>#include <poppack.h>
>
>mystruct_t test()
>{
> unsigned int n = 0xffff0001;
> return (mystruct_t)n;
>}
>
>int main()
>{
> mystruct_t s = test();
> return 0;
>}
Oops, posted to wrong group. Meant for comp.lang.c.
|