N
narechk
Consider:
// points to a valid, alloc:ed, aligned memory location
char* ptr_aligned = xxx;
// same but unaligned obviously
char* ptr_unaligned = xxx + 1;
// write short val to aligned_ptr
*(short*)ptr_aligned = val;
// write short val to unaligned_ptr
*(short*)ptr_unaligned = val;
printf("Ok.");
On most platforms this prints Ok. On sparc-solaris this spits out
SIGSEGV and coredumps.
Question: exactly what does the std say about this? UB? Then how does
one implement ie optimized memcpy without knowing alignment
requirements of target hardware?
Thanks,
- NK
// points to a valid, alloc:ed, aligned memory location
char* ptr_aligned = xxx;
// same but unaligned obviously
char* ptr_unaligned = xxx + 1;
// write short val to aligned_ptr
*(short*)ptr_aligned = val;
// write short val to unaligned_ptr
*(short*)ptr_unaligned = val;
printf("Ok.");
On most platforms this prints Ok. On sparc-solaris this spits out
SIGSEGV and coredumps.
Question: exactly what does the std say about this? UB? Then how does
one implement ie optimized memcpy without knowing alignment
requirements of target hardware?
Thanks,
- NK