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

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -