I am trying to make a memcpy_s() call. Below is my code snippet where I am observing warning " error: implicit declaration of function ‘memcpy_s’; did you mean ‘memcpy’? [-Werror=implicit-function-declaration]"
#include <stdio.h>
#include <string.h>
#include <stdint.h>
static const uint32_t ab[10] = {0,1,2,3,4,5,6,7,8,9};
void main()
{
uint32_t u[10];
memcpy_s((void *)&u[0], sizeof(u), (void *)&ab[0], 10 * sizeof(uint32_t));
}
1条答案
按热度按时间yhxst69z1#
It appears that the IDE/Platform you are using doesn't support the
memcpy_s()
variant ofmemcpy
, which IMO is good! I'd recommend usingmemcpy()
instead.If you haven't already used it before --
Looking at the reference page for
memcpy
void *memcpy(void *restrict dest, const void *restrict src, size_t n);
It needs the following arguments:
dest - pointer to the object to copy to
src - pointer to the object to copy from
n - number of bytes to copy
So,
Or better,
with a minimalistic, not-so-perfect macro to get count of elements in the array:
By the way, there is a typo in your code:
is the parenthesis. If you at all migrate to a platform where you have
memcpy_s()
supported then change it to:Update:
I learnt from OP that the actual assignment is to write a function which behaves like
memcpy()
. Assuming the nature of arguments to remain consistent with whatmemcpy()
needs, adding areturn
to indicate if the copy happened successfully, you can of course add more.A bare-minimum, simple version can be programmed as: