M
Mark
Hi,
I have stuck with simple problem -- to copy number of bytes.
#define MAX_QUEUES 4
static int gweights[MAX_QUEUES] = { 1, 2, 3, 4 };
int foo (int *weights)
{
if (!weights)
return -1;
/* weights is actually an array defined by the caller */
memcpy(weights, gweights, MAX_QUEUES * sizeof weights);
return 0;
}
It looks to me that code is correct, i.e. it will copy (MAX_QUEUES * sizeof
weights) bytes from source to destination. Given that the size of pointer on
my system is always 32bit, then regadless of MAX_QUEUE value the resulting #
of bytes is correct. Is my reasoning right, or I'm missing something?
I have stuck with simple problem -- to copy number of bytes.
#define MAX_QUEUES 4
static int gweights[MAX_QUEUES] = { 1, 2, 3, 4 };
int foo (int *weights)
{
if (!weights)
return -1;
/* weights is actually an array defined by the caller */
memcpy(weights, gweights, MAX_QUEUES * sizeof weights);
return 0;
}
It looks to me that code is correct, i.e. it will copy (MAX_QUEUES * sizeof
weights) bytes from source to destination. Given that the size of pointer on
my system is always 32bit, then regadless of MAX_QUEUE value the resulting #
of bytes is correct. Is my reasoning right, or I'm missing something?