struct into a matrix

struct as input parameter

Page 1 of 1

1 Replies - 3352 Views - Last Post: 08 July 2009 - 07:57 PM Rate Topic: -----

#1 Beca   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 05-June 08

struct into a matrix

Posted 08 July 2009 - 09:05 AM


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


Is This A Good Question/Topic? 0
  • +

Replies To: struct into a matrix

#2 gdismbit   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 08-July 09

Re: struct into a matrix

Posted 08 July 2009 - 07:57 PM


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);


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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1