Re: is using memcopy() to manipulate arrays appropriate??
On Wed, 9 Oct 2013 16:18:06 -0700 (PDT)
matt d <matt.doolittle33@googlemail.com> wrote:
decode_hamming(uint16_t encoded_lcw)
.....
memcpy(edata, (encoded_lcw+10*index), 10);
encoded_lcw is an integer, specifically uint16_t. The second parameter
to memcpy(3) takes a pointer, specifically void*. Thus the error:
lcw_ecc.h:21:37: error: invalid conversion from ?uint16_t* {aka short
unsigned int*}? to ?uint16_t {aka short unsigned int}?
(Note the '*' in the message.)
Given your description, I suspect perhaps your function wants to take
an integer pointer and element count.
memcpy((rs_codewords+index*6), edata, 6);
rs_codewords is commented out in the code you provided. Note that if
you redefine the function to return a pointer, you'll either want the
caller to provide the buffer or define it statically in the function.
int encoded[11],syndrome[4];
...
syndrome[i]+=(edata[j]*hmatrix[i][j]);
You seem to assume here that syndrome is initialized to zeros. It's
not, or at least won't always be. You can say
int syndrome[4] = {0};
because the standard says that remaining elements are initialized to
the the last provided initialization value. Roughly.
Second I am not sure using memcopy() for this task is the appropriate
memcpy, you mean ...
(ie. most efficient approach this side of using bitwise operations)
approach to solving the task of manipulating these arrays
I don't see any need for memcpy or edata. Why not test the values in
the input array, and write the result directly to rs_codewords? If you
use a pointer into each one, you can index off it. Approximately:
uint16_t *edata = rs_codewords + 6 * index;
/* ... */
edata[j]=!edata[j];
That said, I suspect the code has more serious problems. The comments
refer to a 144-bit output and an input of 24 10-bit words. The code
never tests a bit, though; it seems to treat each uint16_t as a bit,
assigning 0 or 1 to the output.
I would imagine that the input is conventionally an unaligned
bitstring, and that your intermediate representation would be an array
of 24 bit-fields, from which you would construct each output byte
with series of shift operations.
HTH.
--jkl
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]