Posts

Showing posts from April 2, 2019

How to avoid run-time checks for running parts of code that become unreachable after compilation?

Image
7 0 My program gets a couple of Boolean variables from the user, and their values won't change afterwards. Each Boolean variable enables a part of code. Something like this: #include <iostream> void callback_function(bool task_1, bool task_2, bool task_3) { if (task_1) { std::cout << "Running task 1" << std::endl; } if (task_2) { std::cout << "Running task 2" << std::endl; } if (task_3) { std::cout << "Running task 3" << std::endl; } } int main() { bool task_1 = true; bool task_2 = false; bool task_3 = true; while (true) { callback_function(task_1, task_2, task_3); } return 0; } Now my question is, since the Boolean variables are fixed every time the program calls callback