Hi Experts,
What is the key difference between if/else and swtich case statements ?
How the modern ARM GCC compilers handles it ?
It depends. Straightforwardly if's are a test and branch whereas switches use a table for dense ranges - but there are a very large number of variations.
You can see what happens for things you are interested in by using the -S option and looking at the .s assembler file that comes out.
You might also like to look at this free book
http://beginners.re/Reverse_Engineering_for_Beginners-en.pdf
The site "Reverse Engineering for Beginners" free book has been set up by the author about it
In addition to what daith said, switch statements lend themselves to being more easily optimised into jump/branch tables, rather than a series of compares, which can improve performance in some use cases.
Hi Daith,
I am fond of that book.
Thanks for the mention.
Regards,
Tehcguyz
If you really want to know what the compiler does about them you should start looking up things like static single assignment (SSA) and phi functions. Compilers can be a bit tricky in some areas but the source for how things like conditionals are handled and optimized for each particular architecture is really quite readable and almost user friendly nowadays.