Skip to main content
gamedev.net
🔒 Locked

Empty functions

Started by ToohrVyk Nov 1, 2004 at 5:13 AM 0 replies 550+ views
Original Post
ToohrVyk
ToohrVyk
I'm working on multiplatform games right now, and I wanted to deal with multiple versions without resorting to interlocking #ifdef's in my code. My idea was to split up code into several functions, and then have certain functions do something else depending on the platform. What I want to know is, if one of these functions does strictly nothing, will a decent optimizer remove any calls to it?
SiCrane
SiCrane
Maybe.

Link time optimization isn't broadly implemented at this time, so if the functions live in completely separate translation units, empty functions may still generate their calls. And since you're working on cross platform gaming, it's almost assured that at least one of your compilers won't support link time optimization.

However, if you define your functions as inlined in header files and use include paths (or whatever other mechanism you want) to pull the platform specific headers with the correct inline function definitions then the empty bodies would be eliminated as much as any other empty inline function. (i.e. limited to the maximum inlining depth of the the compiler or other optimization preferences.)

You can make these inlined header functions for platforms where the functions are no-ops be simple forwarding functions to real implementations which would limit unnecessary dependencies.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.