S
Shao Miller
Does the following code imply undefined behaviour?
int main(void) {
union {
char bar[1];
char baz[2];
} foo;
foo.baz[0] = 'z';
foo.baz[1] = 'z';
foo.bar[0] = 'r';
return foo.bar[1]; /* Undefined behaviour for O.O.B. */
}
I don't believe it does, since I believe that 'foo.bar' "decays" to a
'char *' whose bounds are checked, if at all, against the substrate of
'foo' versus a 'char[1]' within the object "space" of 'foo'.
I am not at all interested in arguing or debating about it. When in
doubt, treat as undefined, perhaps.
I'd simply be interested in what others have to say about it.
Ben Bacarisse brought up something [I believe is] related in another
thread and Richard Heathfield and Peter "Seebs" Seebach both
additionally shared interesting thoughts on the matter.
So what are your thoughts, if you please?
A good brain-teaser, Ben!
int main(void) {
union {
char bar[1];
char baz[2];
} foo;
foo.baz[0] = 'z';
foo.baz[1] = 'z';
foo.bar[0] = 'r';
return foo.bar[1]; /* Undefined behaviour for O.O.B. */
}
I don't believe it does, since I believe that 'foo.bar' "decays" to a
'char *' whose bounds are checked, if at all, against the substrate of
'foo' versus a 'char[1]' within the object "space" of 'foo'.
I am not at all interested in arguing or debating about it. When in
doubt, treat as undefined, perhaps.
I'd simply be interested in what others have to say about it.
Ben Bacarisse brought up something [I believe is] related in another
thread and Richard Heathfield and Peter "Seebs" Seebach both
additionally shared interesting thoughts on the matter.
So what are your thoughts, if you please?
A good brain-teaser, Ben!