I have a typedef:
typedef unsigned char MyType[2];
I pass it to a function and the result is FAIL!
void f(MyType * m)
{
*m[0] = 0x55;
*m[1] = 0x66;
}
void main(void)
{
Mytype a;
a[0] = 0x45;
a[1] = 0x89;
f(&a);
}
The manipulation of variable a
in main()
works on 1 byte indexing, so a
is equal to {0x45, 0x89}. However in function f
the indexing acts on 2 bytes (the sizeof
the type).
So in function f
, *m[1]
in this instance is actually modifying memory out of bounds.
Why is this, what have I forgotten?
Thanks.