標準では、 standard-layout-structの内部 (先頭ではない) にもパディングがある可能性があると述べているため、バイナリ コピーは移植できない可能性があります。ただし、特定のシステムと梱包指示 (ルックアップ#pragma pack) があれば、 を使用できる場合がありますmemcpy。
次のことを試すことができます。
#include <cstring>
#include <algorithm>
#include <iterator>
#include <iostream>
// look up your compiler's documentation
//#pragma pack(4)
struct fs {
float x, y, z;
};
int main() {
fs b = {1.0, 2.0, 3.0};
float p[ 4 ] = {0};
static_assert( sizeof b == sizeof p - 1, "warning: padding detected!" );
std::memcpy(&p[ 0 ], &b, sizeof p - 1);
std::copy(&p[ 0 ], &p[ 0 ] + 3, std::ostream_iterator<float>(std::cout, "\n"));
}