Last active
May 24, 2024 06:31
-
-
Save m1lkweed/3be672402c43ac5697f1e29bcb79e004 to your computer and use it in GitHub Desktop.
Porting python's `for`/`else` to C with no `setjmp`.
This file contains 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> | |
#define py_for(...) for(int loop_flag = 2, break_called = 0; loop_flag && !break_called; --loop_flag)if((loop_flag == 2) && !break_called)for(__VA_ARGS__, break_called = 0)if((break_called = 1), 0){}else | |
#define py_whl(...) py_for(;__VA_ARGS__;(void)0) | |
int main(){ | |
py_for(int i = 0; i < 5; ++i){ | |
printf("%d\n", i); | |
}else{ | |
puts("egg"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Your move, @Oderjunkie.