davidbrown wrote on Thursday, April 14, 2016:
You have two issues seriously wrong or misunderstood here.
First, FreeRTOS is an operating system. Switches and other C constructs are handled by the compiler, not the OS software. There is nothing that FreeRTOS can do to influence how the compiler generates code for a switch statement. If you don’t understand what compilers do and how an RTOS fits in the development process, then you really need to go on some courses or read an introductuary book - this is very basic stuff.
Secondly, the way a compiler translates a switch statement will vary greatly depending on the details of the source code, the compiler in question, and the choice of optimisation flags. I think it would be very rare for it to involve a runtime call, at least on an ARM processor. Typical implementations can include jump tables, calculated jumps, if-then-else jumps, and if-then-else conditional execution instructions, but compilers are free to be more “imaginative”. You should write your code in the clearest manner possible, ensure that you have appropriate optimisation flags enabled, and let the compiler figure out the best way to generate the code. It is rare that it makes sense to try to influence the details of code generation - usually you will do more harm than good with ideas like “if-then-else is faster than switch”, as human programmers are notoriously poor at spotting the real bottlenecks.