I have been asked to replace arrays in a C struct by C++ std::array
. The C struct is a packed struct that directly translates into memory from an input buffer. Something like:
struct [[gnu::packed]] s {
int a;
int b[5];
int c;
};
struct s s1;
So that struct was being filled with a simple call to memcpy:
std::memcpy(s1, buff, sizeof(s1));
Now I should have something like:
struct [[gnu::packed]] sxx {
int a;
std::array<int, 5> b;
int c;
}
However, I'm concerned that the std::array
may be having some secret stuff in the end of it (to keep info about its size, for example), and that it may break the ability to fill struct sxx
with the same simple std::memcpy()
call.
Can std::array
s transparently replace C arrays in packed structs, or do I need to assign elements separately to avoid memory layout issues?