Hi,
I have an array of chars at a function and I would like to return a pointer so the data will be available from outside. I encounter a compilation error: cannot convert from 'unsigned char [8]' to 'unsigned char *[]'
*id = xlEvent.tagData.msg.id;
*msg = xlEvent.tagData.msg.data;// data is unsigned char[8]. Any problem?
*flag = xlEvent.tagData.msg.flags;
.
.
return status
}
main {
.
.
int hdl = 0;
unsigned char data[8];
unsigned int flags;
lond id;
You cannot just assign pointers like this and expect data to be copied. That's why C++ programmers use strings and vectors for what you are attempting to do. Otherwise, you have to explicitly copy the data pointed to by xlEvent.tagData.msg.data into the msg buffer. You don't explain why you have so many levels of pointer indirection. It wouldn't seem to be necessary based on what you've described so far.
I use SDK and at the CanRead function I call to one of the SDK functions:
stat = xlRecieve(xlPortHandle, &pEventCount, &xlEvent);
the xlEvent class has many objects, one of them is the data (unsigned char[8]) but also the id and flags.
As I can get the id and the flags (not array but single element) at the main function , I would like to get the data which is an array.
you mentioned I can explicitly copy the data to msg buffer. How do I do that ?