Part Number: TMS320F28377D
Tool/software: TI C/C++ Compiler
For debug purposes, e.g. profiling, I am trying to output an array of function pointers via a stream peripheral, e.g. SPI, UART. This requires converting the function pointers into data so they can be written to the peripheral's transmit register.
I have tried in vain to find a standard C (C89/C90/C99) method for converting from a function pointer to data.
For example, casting from a function pointer to data type is undefined behaviour, regardless of the integer type, be it uint32_t (applicable for this platform), uint64_t, or even uintptr_t:
uint32_t dataFromFunc(void (*func)(void)) {
return (uint32_t)func;
}
Likewise casting from a function pointer to a void (data) pointer is undefined behaviour, so the following is also not allowed due to the implicit cast:
void memcpyFuncToData(void *data, void (*func)(void))
{
memcpy(data, func, sizeof(data));
}
Please can you tell me what method I can use that is supported by the compiler, or do I need to drop down to assembly to avoid the undefined behaviour of what I want to do?