Can you do 'unions' with pv-wave? [message #3189] |
Fri, 18 November 1994 17:23 |
jgavin
Messages: 1 Registered: November 1994
|
Junior Member |
|
|
Is there a way to have a single variable viewed as multiple types, similar
to the way unions work in C. For example:
union x {
char a[2];
int b;
};
union x m;
m.a[0] = '\0';
m.a[1] = 'A';
printf ("%d", m.b);
produces the output => 65
In other words, the characters '\0','A' were interpreted as a single integer.
I'm trying to reference a single variable (i.e. 'm') as different types, without
having to make a copy.
The real problem involves a HUGE binary matrix with multiple types intermixed.
We would like to read a single copy of the matrix, and then view it differently
(to avoid multiple copies). Some variables are 8-bit integers, 16-bit int,
float, doubles, so-on-and-so-on.
Our brute-force approach is to read the 50MB file in once as an array of bytes, then again as an array of int, float, then double. This takes time and space
when actually, we simply want to view the same exact data in different ways.
Again, the 'C' union structure is the best way I can describe the problem.
Thanks for any help.
Regards,
Jeff
--
Jeff Gavin Jeff.Gavin@dseg.ti.com
Texas Instruments MSG: JGAV / (214) 462-5496
|
|
|