void function (uint16_t * data)
{
// do something
}
I want to pass my structure to the function as a data but the type is different. How could i do this? I cannot change the Parameter type of *data to struct or anthing else. suggestions please
Also on unions: writing to one field and then reading from other is technically an undefuned behavior. Struct with references or wrapper function is probably the best approach.
(Passing pointer to first element of structure to threat it as array will not work either as compiler can add paddding between members which is forbidden for arrays)
This function's parameter data seems to be pointer to an array with fixed length.
Stupid or not, the description of the function must tell what it requires and what it provides (i.e the interface) and you must pass it the required data.
In other words, if your friend (function) is hungry (needs array of 7 uint16_t), then you should not attempt to shovel a Ferrari (struct A) down his throat.