Pages: 1 [2]   Go Down
Author Topic: Scope problem  (Read 1029 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
Karma: 0
Posts: 183
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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


North Queensland, Australia
Offline Offline
Edison Member
Karma: 74
Posts: 2209
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Here is a type safe method.

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

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

Offline Offline
Shannon Member
Karma: 223
Posts: 12630
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Global Moderator
Offline Offline
Brattain Member
Karma: 308
Posts: 26469
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Pages: 1 [2]   Go Up
Jump to: