Treat C cstyle array as std::array

As discussed in this post
Is std::array<T, S> guaranteed to be POD if T is POD?

std::array<int, N> is POD and thus standard layout. As far as I understand the standard layout requirements, this means that the pointer to the object is identical to the pointer to the first member. Since std::array has no private/ protected members (according to, this should agree with the first element in the wrapped array. Thus something like

reinterpret_cast< std::array<int, 5>* >( &data )

is in my opinion guaranteed to work by the standard. I have to admit, though, that I sometimes have difficulties interpreting the standard language, so please correct me if I am wrong.


Leave a Comment