better code
Posted May 31, 2003 6:04 UTC (Sat) by
tjc (guest, #137)
In reply to:
better code by dododge
Parent article:
strlcpy()
Pointer comparison is undefined if the pointers are not within the same object, so this is not portable standard C.
I've heard of this, but I have never read a good explanation. I just assumed that this restiction has something to do with pointer aliasing. If you understand this, now is the time to show off! ;-)
memmove is safe for overlapping regions, and since it's part of the standard library it's allowed to use architecture-specific magic to compare arbitrary pointers.
How is the performance of memmove()? Does it copy memory a double word at a time? I couldn't find a general way to do this without using architecture-specific magic as you say, so I fell back to memcpy().
BTW, s/int len, i/size_t len/ above. I noticed this about 100ns after I posted. Always use -Wall...
(
Log in to post comments)