Why does wmemcpy exist when memcpy should be enough?

wmemcpyseems to perform the same operations as memcpy, but accepts wchar_t*instead void*. How is its existence justified if these two pieces of code should have the same behavior? Does it have a useful purpose?

memcpy(dest, wchar_array, sizeof(wchar_array));

and

wmemcpy(dest, wchar_array, sizeof(wchar_array) / sizeof(wchar_t));
+4
source share
2 answers

In addition to davmac's answer about API symmetry and having an array size that is not always provided, it should be emphasized that the third argument wmemcpyrefers to the number of elements to be copied (and not to bytes).

wchar_t <wchar.h>, . wcslen, , C wchar_t , wcschr wcsrchr wchar_t *, "" -of-.

P.S. wchar_t , wmemcpy , sizeof(wchar_array), :

#define SIZE 40
wchar_t wchar_array[SIZE];
// ...
wmemcpy(dest, wchar_array, SIZE);
+1

, API, , , ( ).

, , char, #define memcpy. wchar_t wmemcpy. - ( char, wchar_t); , , sizeof .

, API Win32 : UNICODE, ( W), "" ( A); TCHAR char wchar_t ; .. , .

, ; C . , calloc , malloc, memset, ; .

+2

All Articles