<well_doing@yahoo.comwrote in message
news:1193845462.482762.238270@y42g2000hsy.googlegr oups.com...
Quote:
>I have something like this in declaration.
>
union allInOne{
struct simple_s {
int a;
int b;
} s;
struct complex_s {
int a;
int b;
int rec[10];
} c;
} *p;
>
In my code, how to implement something like this,
>
if ( condition A ) {
struct simple_s *ptr = &p->s;
} else {
struct complex_s *ptr = &p->c;
}
>
ptr->a = 0;
ptr->b = 1;
if ( !condition A) {
ptr->rec[1] = 1;
...
}
I see no need any of this in the code you supplied. From what I see of the
structure you will have two int, a and b and an optional array of 10 ints.
In this case, either of the a or b should take the same offset into the
union. So why can't you simply do:
struct allInOne {
int a;
int b;
rec[10];
};
and only use the rec array if !condition A
Perhaps if you explain what you are trying to achieve a good algorithm could
be shown.