this is my first question here, please notice I'm very new to coding. Quick search doesn't helped me since I think the answer might be too simple.
Im writing some code in CAPL (a CANoe specific language based on C). Lets have my scenario simplified: I have to read 10 values Input, but I'm just able to read one by a time (due to HW reasons).
My value is stored in a buffer (rsBuf), now I'm trying to define a help-array for everytime I read the value (rsBuf1 ... 10). At the end I will create another array with added values of rsBuf1 ... rsBuf10.
for every "read-action", I want to define rsBuf1 = rsBuf; rsBuf2 = rsBuf; and so on...
error: for "rsBuf1 = rsBuf;" Error 1112 at (732,16): operand types are incompatible. Compilation failed -- 1 errors, 0 warnings
my "real" values:
variables
{
byte rsBuf[1024];
byte rsBuf1[1024];
}
is there an easy way to do this one-array-from-another? I also tried some other notations I found, like rsBuf1 = {rsBuf}, but wasn't helping. Of course I could define rsBuf1[1]=rsBuf[1]; ... rsBuf1[1024]=rsBuf[1024];
but that would be a waste of time I guess. Thanks in advance, cheers Robert
You can't copy arrays through assignment in C, because the syntax does not allow it. The best solution is to use the memcpy
function.
Alternatively, if it makes sense for the program design, you could put the arrays inside a wrapper struct:
typedef struct
{
int array [5];
} array_wrapper_t;
array_wrapper_t this = {1,2,3,4,5};
array_wrapper_t that;
that = this;
This should yield identical machine code as a call to memcpy
.