Go Down

Topic: Scope problem (Read 2532 times) 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];

https://forum.arduino.cc/index.php?action=dlattach;topic=327736.0;attach=128670 New EEPROM library released


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

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131