Go Down

Topic: Scope problem (Read 1 time) previous topic - next topic


Thanks a lot for the info. Gave me a lot of good ideas, mostly about the efficiency of unions.



The union method is becoming very popular, avoids nasty casts with pointers and provides a nice OO syntax.

Here is a type safe method.

Code: [Select]
template< typename _Type > union Serializer{
  _Type  value;
  byte    data[ sizeof( _Type ) ];

//You would use like
class itg3200
Serializer< int > output[3];


If you wanted to be really clever, you could do this:

If you don't actually need to access the data as an integer, you could use a struct rather than a union.
I only provide help via the forum - please do not contact me for private consultancy.


And it proves that people are just subjective

Speak for yourself!   :smiley-yell:
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Go Up