Changeset View
Changeset View
Standalone View
Standalone View
lib/libc/string/mempcpy.c
Show All 31 Lines | |||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | ||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
#include <string.h> | #include <string.h> | ||||
void * | void * | ||||
mempcpy(void *__restrict dst, const void *__restrict src, size_t len) | mempcpy(void *__restrict dst, const void *__restrict src, size_t len) | ||||
{ | { | ||||
return ((char *)memcpy(dst, src, len) + len); | return (void *)((unsigned char *)memcpy(dst, src, len) + len); | ||||
dim: I'm not sure what is gained here except more characters? The end cast to `void *` is not needed… | |||||
Done Inline ActionsWhy? unsigned isn't needed, and implicit casts to void * are legal C. jrtc27: Why? unsigned isn't needed, and implicit casts to `void *` are legal C. | |||||
Done Inline ActionsComments still apply; zero reason to change the char to u_char below. Then you don't need to include a new header too. jrtc27: Comments still apply; zero reason to change the char to u_char below. Then you don't need to… | |||||
Done Inline Actionsis char * always one byte? if so then you are right gfunni234_gmail.com: is char * always one byte? if so then you are right | |||||
Done Inline Actionssizeof(char) == sizeof(signed char) == sizeof(unsigned char) == 1 by definition jrtc27: `sizeof(char) == sizeof(signed char) == sizeof(unsigned char) == 1` by definition | |||||
} | } |
I'm not sure what is gained here except more characters? The end cast to void * is not needed, it is implicit because of the return type. Changing the inner cast from char * to unsigned char * also does not have any effect, since the pointers are never dereferenced. The original seems clearer to me, and less obfuscated.