Hello!
I'd like to know what can I do if I have a function like this:
"unsigned char function1( char* array)"
and then I need to use an "struct" as input parameter of "function1".
I can't change the source of the function and actually I shouldn't change the struct either, because it was define with typedef and it is used in many other programms.
The struct has 12 elements, some of them are also arrays like this:
unsigned char parameter1[8];
float parameter2[8];
int parameter2[2][2][2];
Thank you very much for your help in advance.
Best regards
Beca
struct into a matrixstruct as input parameter
Page 1 of 1
1 Replies - 777 Views - Last Post: 08 July 2009 - 07:57 PM
Replies To: struct into a matrix
#2
Re: struct into a matrix
Posted 08 July 2009 - 07:57 PM
Hi,
From what you've provided I take it that your function wants a pointer to an array of char's, so that's what you'll have to give it, i.e. you'll have to convert that data from the struct into that format. Copy data to a character array and assign the address of the array to a char pointer which you then use as the argument in the call to the function.
Obviously this has some issues, as not all the data within the struct are of the char data type. It would be helpful to now what the function actually does and if it actually requires all of the data within the struct. For instance, if only the data from the parameter1, the unsigned char array, is required you could assign the address of parameter1 to a char pointer variable and use that as your argument. i.e.
char* ptr1 = reinterpret_cast<char *> (&struct.parameter1);
function1(ptr1);
This would successfully deliver the character data from the parameter1 array into the function. Still as i mention, without knowing the actual usage of the function it's a little difficult to provide a better answer. Anyway, hope this is of use.
From what you've provided I take it that your function wants a pointer to an array of char's, so that's what you'll have to give it, i.e. you'll have to convert that data from the struct into that format. Copy data to a character array and assign the address of the array to a char pointer which you then use as the argument in the call to the function.
Obviously this has some issues, as not all the data within the struct are of the char data type. It would be helpful to now what the function actually does and if it actually requires all of the data within the struct. For instance, if only the data from the parameter1, the unsigned char array, is required you could assign the address of parameter1 to a char pointer variable and use that as your argument. i.e.
char* ptr1 = reinterpret_cast<char *> (&struct.parameter1);
function1(ptr1);
This would successfully deliver the character data from the parameter1 array into the function. Still as i mention, without knowing the actual usage of the function it's a little difficult to provide a better answer. Anyway, hope this is of use.
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote



|