Skip to content

Instantly share code, notes, and snippets.

@superwills
Created February 19, 2024 19:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save superwills/0683895314c7d7831b077e39aff21d45 to your computer and use it in GitHub Desktop.
Save superwills/0683895314c7d7831b077e39aff21d45 to your computer and use it in GitHub Desktop.
First run
#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