This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

mixed vartype buffer in C

I would like to work on a simple communication buffer array abBuf[6][7], that contains all kind of data (8 and 16bit and string) directly without type conversions etc.

Example: I have a 16byte variable X stored at abBuf[3][1] and abBuf[3][2]. The order (big endian) corresponds to a normal unsigned int variable. Is there a sort of elegant typecast or definition in C possible that would allow me to printf(%u,???) or use its value as 16bit variable in a formula etc besides the definition of a big union?

Werner

Parents
  • What's wrong with a union - that's the natural way to do it!

    It wouldn't have to be one huge union - you could make an 8/16-bit union (or whatever), and have an array of them.

    Or try putting "htons" into your favourite internet search engine.

Reply
  • What's wrong with a union - that's the natural way to do it!

    It wouldn't have to be one huge union - you could make an 8/16-bit union (or whatever), and have an array of them.

    Or try putting "htons" into your favourite internet search engine.

Children
No data