The n869 draft says:
J.2 Undefined behavior
[#1] The behavior is undefined in the following
circumstances:
-- An array subscript is out of range, even if an object
is apparently accessible with the given subscript (as
in the lvalue expression a[1][7] given the declaration
int a[4][5]) (6.5.6).
I am wondering if a cast can change this behaviour to something well
defined, ie if the las following line is ok:
int a[4][5];
a[1][7] = 3; /* <- undefined behaviour */
((int*)a[1])[7] = 42; /* defined or not? */
--
Richard
J.2 Undefined behavior
[#1] The behavior is undefined in the following
circumstances:
-- An array subscript is out of range, even if an object
is apparently accessible with the given subscript (as
in the lvalue expression a[1][7] given the declaration
int a[4][5]) (6.5.6).
I am wondering if a cast can change this behaviour to something well
defined, ie if the las following line is ok:
int a[4][5];
a[1][7] = 3; /* <- undefined behaviour */
((int*)a[1])[7] = 42; /* defined or not? */
--
Richard
Comment