I want to debug my microcontroller program in C by sending strings via UART.
Now I'm facing a problem joining debug strings together, as I have to work with c strings.
I need to have debugMessageOnStack on the stack.
Consider following example: I need a string like "My favorite color is mountbatten pink"
const char debugMessageStart[] = "My favorite color is ";
const char* colors[MAX_COLORS] = {[GREEN] = "green", [ORANGE] = "orange", [PINK] = "mountbatten pink"};
char debugMessageOnStack[DEBUG_MESSAGE_LENGTH];
I know it is pretty easy to calculate DEBUG_MESSAGE_LENGTH by hand, but i want it to be calculated dynamically, so I don't have to recalculate it by hand everytime I add a new color string that's longer than all existing color strings.
Theoretically it should be possible as every string length in colors is known before compiling, but I don't know how I can do it.
Thanks!