c - Union declaration with array pointer? -
i have following union structure:
typedef union message { struct { unsigned short header: 16; unsigned short header2: 16; unsigned int timestamp: 32; unsigned int payload: 32; } pieces; unsigned short whole[6]; }message;
if declare way works
message msg = {.whole={255,255,255,0,255,0}};
i wondering there solution declare union exsisting array? this:
unsigned short arr[] = {255,255,255,0,255,0}; message msg = {.whole=arr};
no, not possible. using name of array has "decay" pointer first element in contexts.
btw, has nothing fact array hidden inside union
. arrays can't assigned , way initialize them using initializer did.
you use memcpy
copy contents, though.
Comments
Post a Comment