S
Shao Miller
Good day to All,
Is the translation and execution behaviour of the following program
well-defined by C99?
Does it matter which member of 'the_ptrs' is last used to modify the
value of 'the_ptrs' object, in this particular instance, if pointers
to structs have the same representation?
Thanks.
Some possibly relevant references from the draft 'n1256.pdf':
- 6.2.5 "Types", point 27 (and non-normative footnote 39)
- 6.5 "Expressions", point 7
- 6.5.2.3 "Structure and union members", points 3 (with non-normative
footnote 82) and 5
- 6.7.2.1 "Structure and union specifiers", point 14
struct foo {
int i;
};
struct bar {
double d;
};
union baz {
struct foo f;
struct bar b;
};
union eep {
struct foo *fp;
struct bar *bp;
};
int main(void) {
union baz the_objs;
union eep the_ptrs;
struct bar *test;
/* Effective type established here */
the_objs.f.i = 5;
/* Effective type established here */
the_ptrs.fp = &the_objs.f;
/* Undefined behaviour? */
test = the_ptrs.bp;
return 0;
}
Is the translation and execution behaviour of the following program
well-defined by C99?
Does it matter which member of 'the_ptrs' is last used to modify the
value of 'the_ptrs' object, in this particular instance, if pointers
to structs have the same representation?
Thanks.
Some possibly relevant references from the draft 'n1256.pdf':
- 6.2.5 "Types", point 27 (and non-normative footnote 39)
- 6.5 "Expressions", point 7
- 6.5.2.3 "Structure and union members", points 3 (with non-normative
footnote 82) and 5
- 6.7.2.1 "Structure and union specifiers", point 14
struct foo {
int i;
};
struct bar {
double d;
};
union baz {
struct foo f;
struct bar b;
};
union eep {
struct foo *fp;
struct bar *bp;
};
int main(void) {
union baz the_objs;
union eep the_ptrs;
struct bar *test;
/* Effective type established here */
the_objs.f.i = 5;
/* Effective type established here */
the_ptrs.fp = &the_objs.f;
/* Undefined behaviour? */
test = the_ptrs.bp;
return 0;
}