There are two problems in your code:
ver = HW_SWversion(READ_VERSION);
reassignsver
, leaking the memory you allocated in the previous lineHW_SWversion
returns a pointer to an automatic variable that immediately goes out of scope. Consequences of accessing this variable are undefined.
The easiest change here would be to change HW_SWversion
to update a pointer to a client allocated instance.
void HW_SWversion(version state, floatCharFunction* ver)
{
/* assign version info */
}
int main()
{
floatCharFunction ver[2];
HW_SWversion(READ_VERSION, &ver);
}
Or, if you want to use dynamically allocated memory
void HW_SWversion(version state, floatCharFunction* ver)
{
/* assign version info */
}
int main()
{
floatCharFunction* ver = malloc(2*sizeof(*ver));
if (ver == NULL) {
printf("out of memory\n");
exit(1);
}
HW_SWversion(READ_VERSION, ver);
free(ver);
}