Loading...
Pages: 1 [2]   Go Down
Author Topic: Scope problem  (Read 460 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 0
Posts: 154
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.


RobertEagle
Logged

North Queensland, Australia
Offline Offline
Edison Member
*
Karma: 31
Posts: 1175
View Profile
WWW
 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.

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

//You would use like
class itg3200
{
private:
Serializer< int > output[3];
protected:
...
Logged


UK
Offline Offline
Tesla Member
***
Karma: 89
Posts: 6326
-
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.
Logged

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

Quote
And it proves that people are just subjective
Speak for yourself!   smiley-yell
Logged

Pete, it's a fool looks for logic in the chambers of the human heart.

Pages: 1 [2]   Go Up
Print
 
Jump to: