I have a piece of code that calls various function pointers in an array. These are read-only in Flash, meaning on the Cortex-M3 I am using they are always in the first 16 KB.
Is there any feature of the Keil compiler to use 16 bits for certain pointers, an attribute or similar? I'm looking to save code space. My first thought was to just have them cast to uint16_t, but I am worried that might interfere with the compiler's ability to optimize.
I wonder if you can save any significant amount of ROM this way. You are only trying to save 2 bytes per function pointer in the array. If the number of pointers is roughly the same as the number of functions, function sizes will dominate massively. If, on the other hand, there are few functions and many (duplicate) function pointers, perhaps you can benefit from addressing the functions with a short (8-bit) index using a look-up table.
Yes, I can save 116 bytes of ROM. I am already indexing these in locations where it's practical. Out of 16KB it's not even 1%, but I am down to around 350 and, if possible, this seems a good way to claw back another 100ish.
I was going to say that the biggest savings come from structuring the program more efficiently, but you probably already know that...