mardi 29 mars 2016

Passing inline functions as arguments

I'm wondering if C++ will still obey the inline keyword when a function is passed as an agument. In the following example, would a new frame for onFrame be pushed onto the stack every time frame() is called in the while loop?

bool interrupt = false;

void run(std::function<void()> frame) {
    while(!interrupt) frame();
}

inline void onFrame() {
    // do something each frame
}

int main() {
    run(onFrame);
}

Or would changing to this have any effect?

void run(std::function<inline void()> frame) {
    while(!interrupt) frame();
}

If you have no definitive answer, can you help me find a way to test this? Possibly using memory addresses or some sort of debugger?

Aucun commentaire:

Enregistrer un commentaire