R
Rui Maciel
Consider the following code:
<code>
struct S1 {
size_t type;
// other declarations
};
struct S2 {
size_t type;
// other declarations
};
//snip. an unspecified number of structs S?
struct Sn {
size_t type;
// other declarations
};
typedef union {
struct S1 *s1;
struct S2 *s2;
// a pointer to each struct S? that has been declared
struct Sn *sn;
} cursor_t;
void foo(void)
{
cursor_t cursor;
struct S1 bar;
// init bar
cursor.s1 = &bar;
}
</code>
Does the C language guarantee that cursor.s2->type to cursor.sn->type will refer to bar.type? If so, will
that still be the case if the programmer assigns &bar to cursor.s2 instead of cursor.s1?
Thanks in advance,
Rui Maciel
<code>
struct S1 {
size_t type;
// other declarations
};
struct S2 {
size_t type;
// other declarations
};
//snip. an unspecified number of structs S?
struct Sn {
size_t type;
// other declarations
};
typedef union {
struct S1 *s1;
struct S2 *s2;
// a pointer to each struct S? that has been declared
struct Sn *sn;
} cursor_t;
void foo(void)
{
cursor_t cursor;
struct S1 bar;
// init bar
cursor.s1 = &bar;
}
</code>
Does the C language guarantee that cursor.s2->type to cursor.sn->type will refer to bar.type? If so, will
that still be the case if the programmer assigns &bar to cursor.s2 instead of cursor.s1?
Thanks in advance,
Rui Maciel