spectral

Improving union with type ?

Discussion created by spectral on Oct 13, 2010
Latest reply on Oct 15, 2010 by himanshu.gautam

I would like to write something like that :

typedef struct
{
 int a;
 float b;
 float c;
} T1;

typedef struct
{
 float a;
} T2;

typdef union
{
 T1 t1;
 T2 t2;
} ValuesSet;

Like this I can access like this :

ValuesSet set;
set.t1.a = 20; 

Today I have to do the following :

typdef
{
union { 
 T1 t1;

 T2 t2;
} all;
} ValuesSet;

 set.all.t1.a = 20;

It is a longer expression :-(

Outcomes