Created
February 19, 2024 19:27
-
-
Save superwills/0683895314c7d7831b077e39aff21d45 to your computer and use it in GitHub Desktop.
First run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main(int argc, const char * argv[]) { | |
struct FirstRun { | |
bool hasRun = 0; | |
operator bool() { | |
bool firstRun = !hasRun; | |
hasRun = 1; | |
return firstRun; | |
} | |
}; | |
for (int i = 0; i < 3; i++) { | |
static FirstRun isFirstRun; | |
if (isFirstRun) puts("1st run"); | |
else puts("subsequent"); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment