3 ms·
> A final interesting property of this code is that its be- haviour is undefined according to the C language standard. The reason is that it calls memcpy() acro
by jxy 6y ago
> A final interesting property of this code is that its be- haviour is undefined according to the C language standard. The reason is that it calls memcpy() across a range of memory comprising multiple distinct C objects, copying them all into memory-mapped storage in a single operation.
What's wrong with memcpy here? As long as dst and src are both non-zero and the ranges of memory are not overlapping, the behavior of memcpy is well defined.
- MaysonL 6y agoStructure alignments…
- jxy 6y agoAs long as the size argument is initialized as sizeof(struct ...), it is totally fine, isn't it?
- rurban 6y agoPointers into a copied region are invalidated. Only GC languages do such memory copying safely. It's also insanely slow with gcc, compared to clang. Like factor 1000 with some compile-time constants.