< Previous | Contents | Next >
Calling an inlined function is no different than calling a non-inlined function, as you see with my first call to radiation().
health = radiation(health);
This line of code assigns health one half of its original value.
Assuming that the compiler grants my request for inlining, this code doesn’t result in a function call. Instead, the compiler places the code to halve health
180 Chapter 5 n Functions: Mad Lib
right at this place in the program. In fact, the compiler does this for all three calls to the function.
Rea l Worl d
Although obsessing about performance is a game programmer’s favorite hobby, there’s a danger in focusing too much on speed. In fact, the approach many developers take is to first get their game programs working well before they tweak for small performance gains. At that point, programmers will profile their code by running a utility (a profiler) that analyzes where the game program spends its time. If a programmer sees bottlenecks, he or she might consider hand optimizations such as function inlining.