Skip to content

Instantly share code, notes, and snippets.

@mtao
Created December 21, 2017 00:23
Show Gist options
  • Save mtao/4a9cfc5f08130578ccbe1fb65fb71eee to your computer and use it in GitHub Desktop.
Save mtao/4a9cfc5f08130578ccbe1fb65fb71eee to your computer and use it in GitHub Desktop.
if (and presumably for) can have static variables in initialization. test is due to me trying to not pollute my namespaces with static variables with imgui Raw
#include <iostream>
void run() {
if(static bool f = false; f) {
std::cout << "true!" << std::endl;
f = false;
} else {
std::cout << "false!" << std::endl;
f = true;
}
}
int main() {
run();
run();
run();
run();
run();
return 0;
}
/*
Example usage stolen from Imgui examples:
if (static bool show_another_window = false; show_another_window)
{
ImGui::Begin("Another Window", &show_another_window);
ImGui::Text("Hello from another window!");
ImGui::End();
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment